diff options
Diffstat (limited to 'lib/vendors/repository.ts')
| -rw-r--r-- | lib/vendors/repository.ts | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/vendors/repository.ts b/lib/vendors/repository.ts index c5362ccf..d2be43ca 100644 --- a/lib/vendors/repository.ts +++ b/lib/vendors/repository.ts @@ -2,7 +2,7 @@ import { and, eq, inArray, count, gt, AnyColumn, SQLWrapper, SQL} from "drizzle-orm"; import { PgTransaction } from "drizzle-orm/pg-core"; -import { VendorContact, vendorContacts, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendors, vendorsWithTypesView, type Vendor } from "@/db/schema/vendors"; +import { VendorContact, vendorContacts, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendorPossibleMaterials, vendors, vendorsWithTypesView, vendorsWithTypesAndMaterialsView, type Vendor } from "@/db/schema/vendors"; import db from '@/db/db'; import { items } from "@/db/schema/items"; import { rfqs,rfqItems, rfqEvaluations, vendorResponses } from "@/db/schema/rfq"; @@ -70,6 +70,33 @@ export async function countVendorsWithTypes( const res = await tx.select({ count: count() }).from(vendorsWithTypesView).where(where); return res[0]?.count ?? 0; } + +/** + * 새로운 확장 뷰를 사용하는 조회 함수 + */ +export async function selectVendorsWithTypesAndMaterials( + tx: PgTransaction<any, any, any>, + { where, orderBy, offset, limit }: SelectVendorsOptions +) { + return tx + .select() + .from(vendorsWithTypesAndMaterialsView) + .where(where ?? undefined) + .orderBy(...(orderBy ?? [])) + .offset(offset ?? 0) + .limit(limit ?? 20); +} + +/** + * 새로운 확장 뷰에 대한 COUNT 함수 + */ +export async function countVendorsWithTypesAndMaterials( + tx: PgTransaction<any, any, any>, + where?: any + ) { + const res = await tx.select({ count: count() }).from(vendorsWithTypesAndMaterialsView).where(where); + return res[0]?.count ?? 0; + } /** @@ -280,9 +307,9 @@ export async function insertVendorMaterial( ) { // returning() 사용 시 배열로 돌아오므로 [0]만 리턴 return tx - .insert(vendorPossibleMateirals) + .insert(vendorPossibleMaterials) .values(data) - .returning({ id: vendorPossibleMateirals.id, createdAt: vendorPossibleMateirals.createdAt }); + .returning({ id: vendorPossibleMaterials.id, createdAt: vendorPossibleMaterials.createdAt }); } export async function selectRfqHistory( |
