diff options
| author | joonhoekim <26rote@gmail.com> | 2025-03-25 15:55:45 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-03-25 15:55:45 +0900 |
| commit | 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch) | |
| tree | 8a5587f10ca55b162d7e3254cb088b323a34c41b /lib/pq/repository.ts | |
initial commit
Diffstat (limited to 'lib/pq/repository.ts')
| -rw-r--r-- | lib/pq/repository.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/pq/repository.ts b/lib/pq/repository.ts new file mode 100644 index 00000000..95daf9a3 --- /dev/null +++ b/lib/pq/repository.ts @@ -0,0 +1,44 @@ +import db from "@/db/db"; +import { pqCriterias } from "@/db/schema/pq"; +import { + eq, + inArray, + not, + asc, + desc, + and, + ilike, + gte, + lte, + count, + gt, +} from "drizzle-orm"; +import { PgTransaction } from "drizzle-orm/pg-core"; + +export async function selectPqs( + 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(pqCriterias) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} +/** 총 개수 count */ +export async function countPqs( + tx: PgTransaction<any, any, any>, + where?: any +) { + const res = await tx.select({ count: count() }).from(pqCriterias).where(where); + return res[0]?.count ?? 0; +} |
