no message
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user