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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for sanic_aiomysql-2022.4.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 752c9a3d1b740326d5b823ba09c0c5209dcd6d9f85e5fdca16f6ba5dc2bffc6f |
|
MD5 | 2bca54b79a34b4727c614cdf28e7d382 |
|
BLAKE2b-256 | ba6d51cc930884ff8aa9dad2a5e10d03893c0719b5bec084ae76a6dc11f63e00 |