Skip to main content

Simple framework for aiomysql

Project description

Aiomysql-Core

Simple framework for aiomysql

Introduce

simple package, easy to use

aiomysql

Document

click me

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'}
    clause = Test.insert().values(**doc)
    rowcount = await core.execute_rowcount(clause)
    print(rowcount)
    # search
    clause = Test.select().where(Test.c.id == 1).limit(1)
    row = await core.get(clause)
    print(row.id, row.content)
    clause = Test.select().where(Test.c.id > 1)
    rows = await core.query(clause)
    async for row in rows:
        print(row.id, row.content)
    # update
    doc = {'content': 'update'}
    clause = Test.update().values(**doc).where(Test.c.id == 1)
    rowcount = await core.execute_rowcount(clause)
    print(rowcount)
    # delete
    clause = Test.delete().where(Test.c.id == 1)
    rowcount = await core.execute_rowcount(clause)
    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.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

aiomysql_core-0.0.7-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aiomysql-core-0.0.7.tar.gz.

File metadata

  • Download URL: aiomysql-core-0.0.7.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

Hashes for aiomysql-core-0.0.7.tar.gz
Algorithm Hash digest
SHA256 28f59cf72fe3eb8db027e1cd915ed69f2e8958848a1a311b4dacc0816fd3d4ee
MD5 8ec9963716b2015fe2839c5082146aca
BLAKE2b-256 c8e767064e831a63548ca82dfc7a29fc1fdd10eaec8ac046a59af5de05849dcf

See more details on using hashes here.

File details

Details for the file aiomysql_core-0.0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: aiomysql_core-0.0.7-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

Hashes for aiomysql_core-0.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 70f6dadf946a1ab6f9003b8472b6ba4aa7e2ffad8485ca14b44d5a80b07048ce
MD5 eabd169d8cab718cdfa081dfeaf6a3ce
BLAKE2b-256 eac23a80c4d329d83640aba3388cb0cb9a0fc01fa22016d0b1d7b6f585ca526f

See more details on using hashes here.

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