Changeset c4dd17d for database/drizzle/queries/components.ts
- Timestamp:
- 12/20/25 04:03:51 (7 months ago)
- Branches:
- main
- Children:
- 5ce5904
- Parents:
- 37bcb87
- File:
-
- 1 edited
-
database/drizzle/queries/components.ts (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/queries/components.ts
r37bcb87 rc4dd17d 1 1 import type { Database } from "../db"; 2 import { componentsTable, suggestionsTable } from "../schema"; 2 import {buildsTable, componentsTable } from "../schema"; 3 import {and, desc, eq, ilike} from "drizzle-orm"; 3 4 4 export async function getComponentSuggestions(db: Database) { 5 export async function getAllComponents(db: Database, limit?: number, q?: string, componentType?: string) { 6 let queryConditions = []; 5 7 8 if (q) { 9 queryConditions.push( 10 ilike(componentsTable.name, `%${q}%`) 11 ); 12 } 13 14 if(componentType && componentType.trim() !== 'all') { 15 queryConditions.push( 16 eq(componentsTable.type, componentType.trim().toLowerCase()) 17 ); 18 } 19 20 const componentsList = await db 21 .select({ 22 id: componentsTable.id, 23 name: componentsTable.name, 24 brand: componentsTable.brand, 25 price: componentsTable.price, 26 }) 27 .from(componentsTable) 28 .where( 29 queryConditions.length > 0 ? 30 and ( 31 ...queryConditions 32 ) 33 : undefined 34 ) 35 .orderBy( 36 desc(componentsTable.price) 37 ) 38 .limit(limit || 100); // 100 placeholder 39 40 return componentsList; 6 41 } 7 42 8 export async function setComponentSuggestionStatus(db: Database, suggestionId: number, status: string, adminComment: string) { 43 export async function getComponentDetails(db: Database, componentId: number) { 44 const [componentDetails] = await db 45 .select() 46 .from(componentsTable) 47 .where( 48 eq(componentsTable.id, componentId) 49 ) 50 .limit(1); 9 51 52 return componentDetails ?? null; 10 53 } 11 12 export async function getAllComponents(db: Database, componentType?: string, q?: string, page?: number, pageSize?: number) {13 14 }
Note:
See TracChangeset
for help on using the changeset viewer.
