Skip to main content

封装aiomysql的异步mysql客户端引擎。

Project description

asmysql

Introduction

asmysql is a library for using the MySQL asynchronous client, which is a wrapper for aiomysql.

Features

  • Code supports type annotations.
  • Very easy to use, simply inherit the AsMysql class for logical development.
  • Supports automatic management of the MySQL connection pool and reconnection mechanism.
  • Automatically captures and handles MysqlError errors globally.
  • Separates statement execution from data retrieval.

Install

# Python3.11+
pip install asmysql

Documentation

Quick Start

import asyncio
from asmysql import AsMysql


class TestAsMysql(AsMysql):
    host = '127.0.0.1'
    port = 3306
    user = 'root'
    password = 'pass'

    async def get_users(self):
        result = await self.client.execute('select user,authentication_string,host from mysql.user')
        if result.err:
            print(result.err)
        else:
            async for item in result.iterate():
                print(item)

                
async def main():
    mysql = await TestAsMysql()
    await mysql.get_users()
    await mysql.disconnect()


asyncio.run(main())

More Usage

import asyncio
from asmysql import AsMysql

class TestAsMysql(AsMysql):
    async def get_users(self):
        result = await self.client.execute('select user,authentication_string,host from mysql.user')
        if result.err:
            print(result.err)
        else:
            return await result.fetch_all()

mysql = TestAsMysql(host='192.168.1.192', port=3306)

async def main():
    await mysql.connect()  # or: await mysql
    print(await mysql.get_users())
    await mysql.disconnect()

asyncio.run(main())

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

asmysql-0.2.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

asmysql-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file asmysql-0.2.0.tar.gz.

File metadata

  • Download URL: asmysql-0.2.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for asmysql-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dd13c24ce66532188050032bf79dba6440c43990728241b66392ce32e12985c9
MD5 9b1798fa87c2aacfd4adc9a50ec7923c
BLAKE2b-256 6fae025f3ba27e2e68bd80ef782456d3e23306760b995652d41256bcc0cca150

See more details on using hashes here.

File details

Details for the file asmysql-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: asmysql-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for asmysql-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbb701e085868fae45fd3497d1f26c51c1510057b9c915b5114eee508b373b2e
MD5 6edd6ce0ec15b90baccf8d4c13edb93d
BLAKE2b-256 d8379150ba6ad86d2cb268c3def38038aba86af0e0a64ae2dd55203c096ddf32

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