Skip to content

jimgreat/sanic_mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sanic_mysql

Mysql support for sanic.

Built on top of aiomysql.

install

You can install this package as usual with pip:

pip install sanic-mysql

Example

    from sanic import Sanic
    from sanic.response import text
    from sanic_mysql import SanicMysql 
    
    app = Sanic(__name__)
    
    app.config.update(dict(MYSQL=dict(host='127.0.0.1', port=3306,
                           user='root', password='pwd',
                           db='mysql')))
    
    SanicMysql(app)
    
    @app.route("/mysql")
    async def mysq(request):
        val = await request.app.mysql.query('select 10')
        return text(val)
                           
    app.run(host="0.0.0.0", port=8000, debug=True, workers=1)
                           

Resources