This commit is contained in:
Donald Zou 2025-05-19 21:43:11 +08:00
parent a5a64eadc7
commit be10a644a0
2 changed files with 5 additions and 45 deletions

View File

@ -59,47 +59,6 @@ def ResponseObject(status=True, message=None, data=None, status_code = 200) -> F
response.content_type = "application/json" response.content_type = "application/json"
return response return response
"""
Database Connection Functions
"""
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
sqldb.row_factory = sqlite3.Row
def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
result = []
try:
cursor = sqldb.cursor()
result = cursor.execute(statement, paramters)
except Exception as error:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
return result
def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'))
sqldb.row_factory = sqlite3.Row
cursor = sqldb.cursor()
with sqldb:
cursor = sqldb.cursor()
try:
statement = statement.rstrip(';')
s = f'BEGIN TRANSACTION;{statement};END TRANSACTION;'
cursor.execute(statement, paramters)
# sqldb.commit()
except Exception as error:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
sqldb.close()
DashboardConfig = DashboardConfig() DashboardConfig = DashboardConfig()
EmailSender = EmailSender(DashboardConfig) EmailSender = EmailSender(DashboardConfig)
_, APP_PREFIX = DashboardConfig.GetConfig("Server", "app_prefix") _, APP_PREFIX = DashboardConfig.GetConfig("Server", "app_prefix")

View File

@ -70,7 +70,7 @@ class WireguardConfiguration:
os.path.join( os.path.join(
self.__getProtocolPath(), self.__getProtocolPath(),
'WGDashboard_Backup', 'WGDashboard_Backup',
data["Backup"].replace(".conf", ".sql"))) data["Backup"].replace(".conf", ".sql")), True)
else: else:
self.createDatabase() self.createDatabase()
@ -213,7 +213,7 @@ class WireguardConfiguration:
) )
) )
except Exception as e: except Exception as e:
print("[WGDashboard] Error: Drop table failed") print("[WGDashboard] Error: Drop table failed - " + str(e))
return False return False
return True return True
@ -314,7 +314,8 @@ class WireguardConfiguration:
insert_stmt = i.insert().values(dict(row)) insert_stmt = i.insert().values(dict(row))
yield str(insert_stmt.compile(compile_kwargs={"literal_binds": True})) yield str(insert_stmt.compile(compile_kwargs={"literal_binds": True}))
def __importDatabase(self, sqlFilePath) -> bool: def __importDatabase(self, sqlFilePath, restore = False) -> bool:
if not restore:
self.__dropDatabase() self.__dropDatabase()
self.createDatabase() self.createDatabase()
if not os.path.exists(sqlFilePath): if not os.path.exists(sqlFilePath):