summaryrefslogtreecommitdiff
path: root/lib/soap/batch-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/soap/batch-utils.ts')
-rw-r--r--lib/soap/batch-utils.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/soap/batch-utils.ts b/lib/soap/batch-utils.ts
index 76127fc2..ff2c3520 100644
--- a/lib/soap/batch-utils.ts
+++ b/lib/soap/batch-utils.ts
@@ -1,4 +1,4 @@
-import { inArray, sql } from "drizzle-orm";
+import { inArray, sql, getTableColumns } from "drizzle-orm";
import db from "@/db/db";
/**
@@ -31,9 +31,14 @@ export async function bulkUpsert<T extends Record<string, unknown>>(
// Build SET clause once, using excluded.* reference for every column except PK / createdAt / id
const buildSetClause = (sample: T) => {
const setObj: Record<string, unknown> = { updatedAt: new Date() };
+ const tableColumns = getTableColumns(table);
+
for (const col of Object.keys(sample)) {
if (col === uniqueCol || col === "id" || col === "createdAt" || col === "updatedAt") continue;
- setObj[col] = sql.raw(`excluded."${col}"`);
+
+ // Drizzle 테이블 스키마에서 실제 데이터베이스 컬럼명 가져오기
+ const dbColumnName = tableColumns[col]?.name || col;
+ setObj[col] = sql.raw(`excluded."${dbColumnName}"`);
}
return setObj;
};