diff options
Diffstat (limited to 'lib/general-check-list/repository.ts')
| -rw-r--r-- | lib/general-check-list/repository.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/general-check-list/repository.ts b/lib/general-check-list/repository.ts new file mode 100644 index 00000000..100975ab --- /dev/null +++ b/lib/general-check-list/repository.ts @@ -0,0 +1,49 @@ +import { generalEvaluations } from "@/db/schema"; +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 selectGeneralCheckLists( + 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 await tx + .select() + .from(generalEvaluations) + .where(where) + .orderBy(...(orderBy ?? [asc(generalEvaluations.createdAt)])) + .offset(offset ?? 0) + .limit(limit ?? 10); +} + +export async function countGeneralCheckList( + tx: PgTransaction<any, any, any>, + where?: any +) { + const result = await tx + .select({ count: count() }) + .from(generalEvaluations) + .where(where); + + return result[0]?.count ?? 0; +}
\ No newline at end of file |
