summaryrefslogtreecommitdiff
path: root/lib/general-check-list/repository.ts
blob: 100975abd00cfc746514ef065e5ac401f10c6aff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}