summaryrefslogtreecommitdiff
path: root/lib/welding/repository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/welding/repository.ts')
-rw-r--r--lib/welding/repository.ts59
1 files changed, 41 insertions, 18 deletions
diff --git a/lib/welding/repository.ts b/lib/welding/repository.ts
index 10e64f58..1e96867b 100644
--- a/lib/welding/repository.ts
+++ b/lib/welding/repository.ts
@@ -1,6 +1,6 @@
// src/lib/tasks/repository.ts
import db from "@/db/db";
-import { ocrRows } from "@/db/schema";
+import { ocrRows, users } from "@/db/schema";
import {
eq,
inArray,
@@ -21,24 +21,47 @@ import { PgTransaction } from "drizzle-orm/pg-core";
* - 트랜잭션(tx)을 받아서 사용하도록 구현
*/
export async function selectOcrRows(
- tx: PgTransaction<any, any, any>,
- params: {
- where?: any; // drizzle-orm의 조건식 (and, eq...) 등
- orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[];
- offset?: number;
- limit?: number;
- }
- ) {
- const { where, orderBy, offset = 0, limit = 10 } = params;
-
- return tx
- .select()
- .from(ocrRows)
- .where(where)
- .orderBy(...(orderBy ?? []))
- .offset(offset)
- .limit(limit);
+ tx: PgTransaction<any, any, any>,
+ params: {
+ where?: any; // drizzle-orm의 조건식 (and, eq...) 등
+ orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[];
+ offset?: number;
+ limit?: number;
}
+) {
+ const { where, orderBy, offset = 0, limit = 10 } = params;
+
+ return tx
+ .select({
+ // ocrRows의 모든 필드
+ id: ocrRows.id,
+ tableId: ocrRows.tableId,
+ sessionId: ocrRows.sessionId,
+ rowIndex: ocrRows.rowIndex,
+ reportNo: ocrRows.reportNo,
+ no: ocrRows.no,
+ identificationNo: ocrRows.identificationNo,
+ tagNo: ocrRows.tagNo,
+ jointNo: ocrRows.jointNo,
+ jointType: ocrRows.jointType,
+ weldingDate: ocrRows.weldingDate,
+ confidence: ocrRows.confidence,
+ sourceTable: ocrRows.sourceTable,
+ sourceRow: ocrRows.sourceRow,
+ userId: ocrRows.userId,
+ createdAt: ocrRows.createdAt,
+
+ // users 테이블의 필드
+ userName: users.name,
+ userEmail: users.email,
+ })
+ .from(ocrRows)
+ .leftJoin(users, eq(ocrRows.userId, users.id))
+ .where(where)
+ .orderBy(...(orderBy ?? []))
+ .offset(offset)
+ .limit(limit);
+}
/** 총 개수 count */
export async function countOcrRows(
tx: PgTransaction<any, any, any>,