Changeset adc31ef for database/drizzle/queries
- Timestamp:
- 01/28/26 23:16:36 (5 months ago)
- Branches:
- main
- Children:
- be22289
- Parents:
- 1b5c18b
- File:
-
- 1 edited
-
database/drizzle/queries/components.ts (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/queries/components.ts
r1b5c18b radc31ef 271 271 networkAdapters: existingComponents.filter(c => c.type === 'network_adapter'), 272 272 soundCards: existingComponents.filter(c => c.type === 'sound_card'), 273 memoryCards: existingComponents.filter(c => c.type === 'memory_card'), 274 opticalDrives: existingComponents.filter(c => c.type === 'optical_drive'), 275 cables: existingComponents.filter(c => c.type === 'cables') 273 276 }; 274 277 … … 277 280 ...existing.networkCards, 278 281 ...existing.networkAdapters, 279 ...existing.soundCards 282 ...existing.soundCards, 283 ...existing.memoryCards 280 284 ].reduce((sum: number, c: any) => { 281 285 if (!c) return sum; … … 319 323 case 'network_adapter': 320 324 case 'sound_card': 325 case 'memory_card': 321 326 compatibleComponents = await getCompatiblePCIeComponents(db, existing, componentType, pciExpressSlotsUsed, limit, sortCondition); 327 break; 328 case 'optical_drive': 329 compatibleComponents = await getCompatibleOpticalDrives(db, existing, limit, sortCondition); 330 break; 331 case 'cables': 332 compatibleComponents = await getCompatibleCables(db, limit, sortCondition); 322 333 break; 323 334 default: … … 920 931 }; 921 932 break; 933 case 'memory_card': 934 table = memoryCardsTable; 935 selectFields = { 936 ...selectFields, 937 numSlots: memoryCardsTable.numSlots, 938 interface: memoryCardsTable.interface, 939 }; 940 break; 922 941 default: 923 942 return []; … … 945 964 946 965 return components; 966 } 967 968 async function getCompatibleOpticalDrives(db: Database, existing: any, limit?: number, sortCondition?: any) { 969 if (existing.opticalDrives && existing.opticalDrives.length > 0) { 970 return []; 971 } 972 973 return db 974 .select({ 975 id: componentsTable.id, 976 name: componentsTable.name, 977 brand: componentsTable.brand, 978 price: componentsTable.price, 979 imgUrl: componentsTable.imgUrl, 980 type: componentsTable.type, 981 driveType: opticalDrivesTable.type, 982 formFactor: opticalDrivesTable.formFactor, 983 interface: opticalDrivesTable.interface, 984 writeSpeed: opticalDrivesTable.writeSpeed, 985 readSpeed: opticalDrivesTable.readSpeed 986 }) 987 .from(componentsTable) 988 .innerJoin( 989 opticalDrivesTable, 990 eq(componentsTable.id, opticalDrivesTable.componentId) 991 ) 992 .where( 993 eq(componentsTable.type, 'optical_drive') 994 ) 995 .orderBy( 996 sortCondition 997 ) 998 .limit(limit || 100); 999 } 1000 async function getCompatibleCables(db: Database, limit?: number, sortCondition?: any) { 1001 return db 1002 .select({ 1003 id: componentsTable.id, 1004 name: componentsTable.name, 1005 brand: componentsTable.brand, 1006 price: componentsTable.price, 1007 imgUrl: componentsTable.imgUrl, 1008 type: componentsTable.type, 1009 lengthCm: cablesTable.lengthCm, 1010 cableType: cablesTable.type 1011 }) 1012 .from(componentsTable) 1013 .innerJoin( 1014 cablesTable, 1015 eq(componentsTable.id, cablesTable.componentId) 1016 ) 1017 .where( 1018 eq(componentsTable.type, 'cables') 1019 ) 1020 .orderBy( 1021 sortCondition 1022 ) 1023 .limit(limit || 100); 947 1024 } 948 1025
Note:
See TracChangeset
for help on using the changeset viewer.
