Skip to main content

Easy to use MySQL for sanic.

Project description

sanic-aiomysql

setup

install

pip install git+https://github.com/tuna2134/sanic-aiomysql.git

Use

from sanic import Sanic, response
from sanic_mysql import ExtendMySQL

app = Sanic("app")
ExtendMySQL(app, auto=True, user="root", host=127.0.0.1, password="hello", autocommit=True)

@app.get("/")
async def main(request):
    await request.ctx.cursor.execute("CREATE TABLE data(name TEXT, value BIGINT)")
    return response.text("create a table")
    
app.run()

or

from sanic import Sanic, response
from sanic_mysql import ExtendMySQL

app = Sanic("app")
ExtendMySQL(app, user="root", host=127.0.0.1, password="hello", autocommit=True)

@app.get("/")
async def main(request):
    async with request.ctx.pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute("CREATE TABLE data(name TEXT, value BIGINT)")
    return response.text("create a table")
    
app.run()

or

from sanic import Sanic, response
from sanic_mysql import ExtendMySQL, cursor

app = Sanic("app")
ExtendMySQL(app, user="root", host=127.0.0.1, password="hello", autocommit=True)

@app.get("/")
@cursor()
async def main(request, connection, cursor):
    await cursor.execute("CREATE TABLE data(name TEXT, value BIGINT)")
    return response.text("create a table")
    
app.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanic-aiomysql-2022.4.17.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

sanic_aiomysql-2022.4.17-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page