mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 12:56:02 +00:00
feat: 基本架构
This commit is contained in:
0
pkg/database/__init__.py
Normal file
0
pkg/database/__init__.py
Normal file
35
pkg/database/manager.py
Normal file
35
pkg/database/manager.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pymysql
|
||||
|
||||
inst = None
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
host = ''
|
||||
port = 0
|
||||
user = ''
|
||||
password = ''
|
||||
database = ''
|
||||
conn = None
|
||||
cursor = None
|
||||
|
||||
def __init__(self, host: str, port: int, user: str, password: str, database: str):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.database = database
|
||||
|
||||
self.reconnect()
|
||||
|
||||
global inst
|
||||
inst = self
|
||||
|
||||
def reconnect(self):
|
||||
self.conn = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password,
|
||||
database=self.database)
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
|
||||
def get_inst() -> DatabaseManager:
|
||||
global inst
|
||||
return inst
|
||||
Reference in New Issue
Block a user