-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
36 lines (28 loc) · 756 Bytes
/
Copy pathdatabase.py
File metadata and controls
36 lines (28 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from mysql.connector.pooling import MySQLConnectionPool
from utilities import *
pool: MySQLConnectionPool = MySQLConnectionPool(
pool_name='pastinfinity',
pool_size=10,
host=HOST_IP,
user=MYSQL_USER,
password=MYSQL_PASSWORD,
database=DATABASE
)
async def execute_get(code: str, parameters: Optional[Any] = None):
connection = pool.get_connection()
cursor = connection.cursor()
try:
cursor.execute(code, parameters)
return cursor.fetchall()
finally:
cursor.close()
connection.close()
async def execute_write(code: str, parameters: Optional[Any] = None):
connection = pool.get_connection()
cursor = connection.cursor()
try:
cursor.execute(code, parameters)
connection.commit()
finally:
cursor.close()
connection.close()