summaryrefslogtreecommitdiff
path: root/lib/vendor-document-list/repository.ts
blob: 43adf7ca7ac3226cb4b5a388529be6a04133fb2e (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
import db from "@/db/db";
import { documentStagesView } from "@/db/schema/vendorDocu";
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 selectVendorDocuments(
    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(documentStagesView)
        .where(where)
        .orderBy(...(orderBy ?? []))
        .offset(offset)
        .limit(limit);
}
/** 총 개수 count */
export async function countVendorDocuments(
    tx: PgTransaction<any, any, any>,
    where?: any
) {
    const res = await tx.select({ count: count() }).from(documentStagesView).where(where);
    return res[0]?.count ?? 0;
}