feat: 添加select导入以支持查询操作
This commit is contained in:
parent
65eada4a6e
commit
b511dbc962
18
DB.py
18
DB.py
@ -802,13 +802,11 @@ class DBSA:
|
||||
# 生成所有视频唯一键 (v_xid, v_name)
|
||||
all_vid_keys = list({(row["v_xid"], row["v_name"]) for row in vid_rows})
|
||||
|
||||
if all_vid_keys: # 仅当有键时才查询
|
||||
conn = _engine.connect()
|
||||
try:
|
||||
# 查询数据库中已存在的视频记录
|
||||
sel_vid = select([
|
||||
video.c.v_xid,
|
||||
video.c.v_name
|
||||
]).where(
|
||||
# 使用SQLAlchemy 1.4+的select语法
|
||||
sel_vid = select(video.c.v_xid, video.c.v_name).where(
|
||||
tuple_(video.c.v_xid, video.c.v_name).in_(all_vid_keys)
|
||||
)
|
||||
result = conn.execute(sel_vid)
|
||||
@ -834,22 +832,24 @@ class DBSA:
|
||||
# ========== 操作记录表去重 ==========
|
||||
final_op_rows = []
|
||||
if op_rows:
|
||||
try:
|
||||
# 生成所有操作记录索引键
|
||||
op_check_keys = [
|
||||
(row["rn"], row["name_title"], row["keyword"], row["v_xid"], row["createtime"])
|
||||
for row in op_rows
|
||||
]
|
||||
|
||||
if op_check_keys: # 仅当有键时才查询
|
||||
try:
|
||||
# 查询数据库已存在的操作记录
|
||||
conn = _engine.connect()
|
||||
stmt = select([
|
||||
# 使用SQLAlchemy 1.4+的select语法
|
||||
stmt = select(
|
||||
video_op.c.rn,
|
||||
video_op.c.name_title,
|
||||
video_op.c.keyword,
|
||||
video_op.c.v_xid,
|
||||
video_op.c.createtime
|
||||
]).where(
|
||||
).where(
|
||||
tuple_(
|
||||
video_op.c.rn,
|
||||
video_op.c.name_title,
|
||||
@ -883,6 +883,8 @@ class DBSA:
|
||||
if index_key not in existing_db_op_keys and index_key not in existing_op_keys_batch:
|
||||
final_op_rows.append(row)
|
||||
existing_op_keys_batch.add(index_key)
|
||||
else:
|
||||
final_op_rows = op_rows[:] # 如果没有键,直接使用所有行
|
||||
|
||||
# ========== 作者表处理 ==========
|
||||
authors_map = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user