import db from "@/db/db"; import { projects } from "@/db/schema"; import { Item, items } from "@/db/schema/items"; import { tagClasses } from "@/db/schema/vendorData"; import { eq, asc, desc, count, } from "drizzle-orm"; import { PgTransaction } from "drizzle-orm/pg-core"; export async function selectTagClassLists( tx: PgTransaction, params: { where?: any; orderBy?: (ReturnType | ReturnType)[]; offset?: number; limit?: number; } ) { const { where, orderBy, offset = 0, limit = 10 } = params; return tx .select({ id: tagClasses.id, projectId: tagClasses.projectId, code: tagClasses.code, label: tagClasses.label, tagTypeCode: tagClasses.tagTypeCode, createdAt: tagClasses.createdAt, updatedAt: tagClasses.updatedAt, // 프로젝트 정보 추가 projectCode: projects.code, projectName: projects.name }) .from(tagClasses) .innerJoin(projects, eq(tagClasses.projectId, projects.id)) .where(where) .orderBy(...(orderBy ?? [])) .offset(offset) .limit(limit); } /** 총 개수 count */ export async function countTagClassLists( tx: PgTransaction, where?: any ) { const res = await tx .select({ count: count() }) .from(tagClasses) .leftJoin(projects, eq(tagClasses.projectId, projects.id)) .where(where); return res[0]?.count ?? 0; }