封装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.1.4.tar.gz
(5.7 kB
view details)
Built Distribution
File details
Details for the file asmysql-0.1.4.tar.gz
.
File metadata
- Download URL: asmysql-0.1.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.11-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ded4a53551be978184c0ce470d5a887ea31b829cb799e249b2d01e0fae1f02a |
|
MD5 | 52af9c423ab1a1aed77df5820250ae56 |
|
BLAKE2b-256 | c21559623e5489ba5157b5dd8e0997cd8b00d9a59eed17b5e1b5ef5318032b83 |
File details
Details for the file asmysql-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: asmysql-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.11-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42b169065396b14750619800ae47ec89123fe06fecf94d83d661477c63f420e7 |
|
MD5 | 68a6c9d96cf21e935ca40be7de041383 |
|
BLAKE2b-256 | 0ff68faa203d189b9568c575048d4a153ecaef8843b85205e2f56148b37345e9 |