mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🎨 提供DBSqla
类 (KimigaiiWuyi/GenshinUID#526)
This commit is contained in:
parent
5a45e56757
commit
10b666d691
@ -8,13 +8,22 @@ from gsuid_core.utils.database.dal import SQLA
|
||||
is_wal = False
|
||||
|
||||
active_sqla: Dict[str, SQLA] = {}
|
||||
active_sr_sqla: Dict[str, SQLA] = {}
|
||||
db_url = str(get_res_path().parent / 'GsData.db')
|
||||
|
||||
|
||||
def get_sqla(bot_id) -> SQLA:
|
||||
if bot_id not in active_sqla:
|
||||
sqla = SQLA(db_url, bot_id)
|
||||
active_sqla[bot_id] = sqla
|
||||
class DBSqla:
|
||||
def __init__(self, is_sr: bool = False) -> None:
|
||||
self.is_sr = is_sr
|
||||
|
||||
def get_sqla(self, bot_id) -> SQLA:
|
||||
return self._get_sqla(bot_id, self.is_sr)
|
||||
|
||||
def _get_sqla(self, bot_id, is_sr: bool = False) -> SQLA:
|
||||
sqla_list = active_sr_sqla if is_sr else active_sqla
|
||||
if bot_id not in sqla_list:
|
||||
sqla = SQLA(db_url, bot_id, is_sr)
|
||||
sqla_list[bot_id] = sqla
|
||||
sqla.create_all()
|
||||
|
||||
@event.listens_for(sqla.engine.sync_engine, 'connect')
|
||||
@ -24,4 +33,10 @@ def get_sqla(bot_id) -> SQLA:
|
||||
cursor.execute('PRAGMA journal_mode=WAL')
|
||||
cursor.close()
|
||||
|
||||
return active_sqla[bot_id]
|
||||
return sqla_list[bot_id]
|
||||
|
||||
def get_gs_sqla(self, bot_id):
|
||||
return self._get_sqla(bot_id, False)
|
||||
|
||||
def get_sr_sqla(self, bot_id):
|
||||
return self._get_sqla(bot_id, True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user