diff options
Diffstat (limited to 'lib/procurement-rfqs/repository.ts')
| -rw-r--r-- | lib/procurement-rfqs/repository.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/procurement-rfqs/repository.ts b/lib/procurement-rfqs/repository.ts new file mode 100644 index 00000000..eb48bc42 --- /dev/null +++ b/lib/procurement-rfqs/repository.ts @@ -0,0 +1,50 @@ +// src/lib/tasks/repository.ts +import db from "@/db/db"; +import { procurementRfqsView } from "@/db/schema"; +import { + eq, + inArray, + not, + asc, + desc, + and, + ilike, + gte, + lte, + count, + gt, sql +} from "drizzle-orm"; +import { PgTransaction } from "drizzle-orm/pg-core"; + +/** + * 단건/복수 조회 시 공통으로 사용 가능한 SELECT 함수 예시 + * - 트랜잭션(tx)을 받아서 사용하도록 구현 + */ +export async function selectPORfqs( + tx: PgTransaction<any, any, any>, + params: { + where?: any; + orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[]; + offset?: number; + limit?: number; + } +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select() + .from(procurementRfqsView) + .where(where ?? undefined) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} +/** 총 개수 count */ +export async function countPORfqs( + tx: PgTransaction<any, any, any>, + where?: any +) { + const res = await tx.select({ count: count() }).from(procurementRfqsView).where(where); + return res[0]?.count ?? 0; +} + |
