Simple framework for aiomysql
Project description
Aiomysql-Core
Simple framework for aiomysql
Introduce
simple package, easy to use
Document
Installation
pip install aiomysql-core
Simple uses
import asyncio
import aiomysql
from aiomysql_core import AioMysqlCore
async def test_example(loop):
pool = await aiomysql.create_pool(host='', port=3306,
user='', password='',
db='', loop=loop)
core = AioMysqlCore(pool=pool)
rows = await core.query('select * from users where uid=%s', 113)
print(rows)
rows = await core.gener('select * from users limit 100')
async for row in rows:
print(row)
row = await core.get('select * from users where uid=%(uid)s', {'uid': 113})
print(row)
rowcount = await core.execute_rowcount('select * from users where uid=%(uid)s', {'uid': 113})
print(rowcount)
pool.close()
await pool.wait_closed()
loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))
Simple SQLAlchemy uses
import asyncio
from aiomysql.sa import create_engine
from aiomysql_core import AioMysqlAlchemyCore
from sqlalchemy import Column, Integer, String, MetaData, Table
metadata = MetaData()
Test = Table('test', metadata,
Column('id', Integer, primary_key=True),
Column('content', String(255), server_default="")
)
async def test_example(loop):
config = {'user': '', 'password': '', 'db': '',
'host': '', 'port': 3306, 'autocommit': True, 'charset': 'utf8mb4'}
engine = await create_engine(loop=loop, **config)
core = AioMysqlAlchemyCore(engine=engine)
# insert
doc = {'content': 'insert'}
query = Test.insert().values(**doc)
rowcount = await core.execute_rowcount(query)
print(rowcount)
# search
query = Test.select().where(Test.c.id == 1).limit(1)
row = await core.get(query)
print(row.id, row.content)
query = Test.select().where(Test.c.id > 1)
rows = await core.query(query)
async for row in rows:
print(row.id, row.content)
# update
doc = {'content': 'update'}
query = Test.update().values(**doc).where(Test.c.id == 1)
rowcount = await core.execute_rowcount(query)
print(rowcount)
# delete
query = Test.delete().where(Test.c.id == 1)
rowcount = await core.execute_rowcount(query)
print(rowcount)
await engine.wait_closed()
loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))
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
aiomysql-core-0.0.6.tar.gz
(3.6 kB
view details)
Built Distribution
File details
Details for the file aiomysql-core-0.0.6.tar.gz
.
File metadata
- Download URL: aiomysql-core-0.0.6.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08455281857dc1056841616d370938b510cbfe49491d4a9259e48318d8357cfb |
|
MD5 | ce6f0f5cb5d47c49d6a8a0b3c3ba348b |
|
BLAKE2b-256 | 7567fde0bd57d3163634345e39887dbe703535b5721d43da0c76a72008026617 |
File details
Details for the file aiomysql_core-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: aiomysql_core-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6925952c8e8da9d749b895faa058bf4012ffcc101f83c1e49a3b083c8c79dbb |
|
MD5 | d4c7408df6bb344ca44d800de6e18434 |
|
BLAKE2b-256 | ecdc46f037b0bf3fd742380cef49c3596ad7e38ea756b02780a7eefb1b6d51c0 |