no message

This commit is contained in:
Cricial
2025-12-13 12:44:15 +08:00
parent a6b06735f6
commit 0e52fcb34b
41 changed files with 42682 additions and 34029 deletions

View File

@@ -11,6 +11,7 @@ import networkx as nx
import json
import pickle
class ControllerDB:
is_with_exp: bool
dct_parameter = None
@@ -382,6 +383,24 @@ class ControllerDB:
db_session.execute(sql)
db_session.commit()
def drop_table(self, table_name, keep_ga_id=None):
"""
删除表中数据或整张表:
- 如果 keep_ga_id 为 None则直接删除整张表。
- 如果 keep_ga_id 有值,则只删除除了该 ga_id 外的记录,保留该 ga_id。
参数:
table_name : str
数据库表名
keep_ga_id : str/int, 可选
需要保留的 ga_id
"""
try:
sql = text(f"DELETE FROM {table_name} WHERE ga_id != :ga_id")
engine.execute(sql, {"ga_id": keep_ga_id})
print(f"[DB] Deleted all rows from `{table_name}` except ga_id={keep_ga_id}.")
except Exception as e:
print(f"[DB] Failed to delete rows from `{table_name}`: {e}")
if __name__ == '__main__':
print("Testing the database connection...")
try: