feat: 批量更新也能够支持按需更新
This commit is contained in:
@@ -203,16 +203,12 @@ async def update(session: AsyncSessionDep, query_config, module_config, debug_da
|
||||
|
||||
row = get_value(query_config, 'row', None)
|
||||
update_by_fields = get_value(query_config, 'updateByFields', env.default_update_by_fields)
|
||||
update_fields = get_value(query_config, 'updateFields', None)
|
||||
|
||||
if row is None:
|
||||
return {
|
||||
"error": "row parameter is missing",
|
||||
}
|
||||
|
||||
if not update_fields and update_by_fields:
|
||||
update_fields = row.keys()
|
||||
|
||||
row_id = get_value(row, 'id', None)
|
||||
|
||||
if row_id is None:
|
||||
@@ -223,7 +219,7 @@ async def update(session: AsyncSessionDep, query_config, module_config, debug_da
|
||||
create_convertor(module_config)['encode_list']([row])
|
||||
|
||||
try:
|
||||
sql, values = build_update_sql(module_config, row, update_fields)
|
||||
sql, values = build_update_sql(module_config, row, row.keys() if update_by_fields else None)
|
||||
|
||||
debug_data.append({"sql": sql, "values": values})
|
||||
await conn.exec_driver_sql(sql, tuple(values))
|
||||
@@ -257,7 +253,7 @@ async def batch_update(session: AsyncSessionDep, query_config, module_config, de
|
||||
conn = await session.connection()
|
||||
|
||||
rows = get_value(query_config, 'rows', None)
|
||||
update_fields = get_value(query_config, 'updateFields', None)
|
||||
update_by_fields = get_value(query_config, 'updateByFields', env.default_update_by_fields)
|
||||
|
||||
if rows is None or len(rows) == 0:
|
||||
return {
|
||||
@@ -274,7 +270,7 @@ async def batch_update(session: AsyncSessionDep, query_config, module_config, de
|
||||
|
||||
try:
|
||||
for row in rows:
|
||||
sql, values = build_update_sql(module_config, row, update_fields)
|
||||
sql, values = build_update_sql(module_config, row, row.keys() if update_by_fields else None)
|
||||
debug_data.append({"sql": sql, "values": values})
|
||||
await conn.exec_driver_sql(sql, tuple(values))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user