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
File details
Details for the file sanic-aiomysql-2022.4.17.tar.gz
.
File metadata
- Download URL: sanic-aiomysql-2022.4.17.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67514800706fd80584eecbd385a018236ae5f78dddec10e45c9b422bf4bc16d3 |
|
MD5 | dd64381763f7576ad76d6f35d1ac1abf |
|
BLAKE2b-256 | bf6a623982fc561004cb27951fb187cddd32270e00d0ff18f4a697188080bb75 |
File details
Details for the file sanic_aiomysql-2022.4.17-py3-none-any.whl
.
File metadata
- Download URL: sanic_aiomysql-2022.4.17-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 752c9a3d1b740326d5b823ba09c0c5209dcd6d9f85e5fdca16f6ba5dc2bffc6f |
|
MD5 | 2bca54b79a34b4727c614cdf28e7d382 |
|
BLAKE2b-256 | ba6d51cc930884ff8aa9dad2a5e10d03893c0719b5bec084ae76a6dc11f63e00 |