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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import db from "@/db/db";
import { projects } from "@/db/schema";
import { Item, items } from "@/db/schema/items";
import { tagTypeClassFormMappings } from "@/db/schema/vendorData";
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 selectFormLists(
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({
id: tagTypeClassFormMappings.id,
projectId: tagTypeClassFormMappings.projectId,
tagTypeLabel: tagTypeClassFormMappings.tagTypeLabel,
classLabel: tagTypeClassFormMappings.classLabel,
formCode: tagTypeClassFormMappings.formCode,
formName: tagTypeClassFormMappings.formName,
createdAt: tagTypeClassFormMappings.createdAt,
updatedAt: tagTypeClassFormMappings.updatedAt,
// 프로젝트 정보 추가
projectCode: projects.code,
projectName: projects.name
})
.from(tagTypeClassFormMappings)
.innerJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id))
.where(where)
.orderBy(...(orderBy ?? []))
.offset(offset)
.limit(limit);
}
/** 총 개수 count */
export async function countFormLists(
tx: PgTransaction<any, any, any>,
where?: any
) {
const res = await tx
.select({ count: count() })
.from(tagTypeClassFormMappings)
.leftJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id))
.where(where);
return res[0]?.count ?? 0;
}
|