This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2023-09-20 20:30:31 -06:00
|
|
|
import pymysql
|
|
|
|
from dbutils.pooled_db import PooledDB
|
|
|
|
|
|
|
|
|
|
|
|
class DatabaseConnection:
|
|
|
|
db_pool: PooledDB = None
|
|
|
|
|
|
|
|
def init_db(self, host, username, password, database):
|
|
|
|
self.db_pool = PooledDB(
|
|
|
|
creator=pymysql,
|
|
|
|
maxconnections=10,
|
|
|
|
host=host,
|
|
|
|
user=username,
|
|
|
|
password=password,
|
|
|
|
database=database,
|
2023-09-23 19:08:30 -06:00
|
|
|
charset='utf8mb4',
|
2023-09-24 13:02:30 -06:00
|
|
|
autocommit=True,
|
2023-09-20 20:30:31 -06:00
|
|
|
)
|
2023-09-24 13:02:30 -06:00
|
|
|
|
|
|
|
# Test it.
|
2023-09-20 20:30:31 -06:00
|
|
|
conn = self.db_pool.connection()
|
|
|
|
del conn
|
|
|
|
|
|
|
|
def connection(self):
|
|
|
|
return self.db_pool.connection()
|
|
|
|
|
|
|
|
|
|
|
|
db_pool = DatabaseConnection()
|