Syntactic sugar for aiomysql
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 272
- PR merge metrics
- No merged PRs in 30d
Description
I successfully use your library in several projects.
I propose a solution to simplify the work with the library.
```python
import asyncio
from CshLib.conn import MySQL
class MySQLModules(MySQL):
user = 'stat'
password = 'bh0020'
db = 'modules'
async def test():
async with MySQLModules() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT Count(*) FROM modules.modules;")
records = await cur.fetchone()
print(records)
asyncio.run(test())
```
MySQL class code
```python
import aiomysql
class MySQL:
host = '127.0.0.1'
port = 3306
user = ''
password = ''
db = ''
async def __aenter__(self) -> aiomysql.connection:
self.conn = await aiomysql.connect(
host=self.host,
port=self.port,
user=self.user,
password=self.password,
db=self.db
)
return self.conn
async def __aexit__(self, exc_type, exc_val, exc_tb):
self.conn.close()
```
Contributor guide
Assessment
This issue has not been assessed yet.