| [fdd776b] | 1 | import { pgTable, serial, integer, text, numeric, boolean, date, primaryKey } from "drizzle-orm/pg-core";
|
|---|
| 2 |
|
|---|
| 3 | export const componentsTable = pgTable("components", {
|
|---|
| 4 | id: serial("id").primaryKey(),
|
|---|
| 5 | name: text("name").notNull(),
|
|---|
| 6 | brand: text("brand").notNull(),
|
|---|
| 7 | price: numeric("price").notNull(),
|
|---|
| 8 | imgUrl: text("img_url"),
|
|---|
| 9 | });
|
|---|
| 10 |
|
|---|
| 11 | // Base Components
|
|---|
| 12 | export const CPUTable = pgTable("cpu", {
|
|---|
| 13 | componentId: integer("component_id")
|
|---|
| 14 | .primaryKey()
|
|---|
| 15 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 16 | socket: text("socket").notNull(),
|
|---|
| 17 | cores: integer("cores").notNull(),
|
|---|
| 18 | threads: integer("threads").notNull(),
|
|---|
| 19 | baseClock: numeric("base_clock").notNull(),
|
|---|
| 20 | boostClock: numeric("boost_clock"),
|
|---|
| 21 | tdp: numeric("tdp").notNull(),
|
|---|
| 22 | });
|
|---|
| 23 |
|
|---|
| 24 | export const GPUTable = pgTable("gpu", {
|
|---|
| 25 | componentId: integer("component_id")
|
|---|
| 26 | .primaryKey()
|
|---|
| 27 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 28 | vram: numeric("vram").notNull(),
|
|---|
| 29 | tdp: numeric("tdp").notNull(),
|
|---|
| 30 | baseClock: numeric("base_clock"),
|
|---|
| 31 | boostClock: numeric("boost_clock"),
|
|---|
| 32 | chipset: text("chipset").notNull(),
|
|---|
| 33 | length: numeric("length").notNull(),
|
|---|
| 34 | });
|
|---|
| 35 |
|
|---|
| 36 | export const memoryTable = pgTable("memory", {
|
|---|
| 37 | componentId: integer("component_id")
|
|---|
| 38 | .primaryKey()
|
|---|
| 39 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 40 | type: text("type").notNull(),
|
|---|
| 41 | speed: numeric("speed").notNull(),
|
|---|
| 42 | capacity: numeric("capacity").notNull(),
|
|---|
| 43 | modules: integer("modules").notNull(),
|
|---|
| 44 | });
|
|---|
| 45 |
|
|---|
| 46 | export const powerSupplyTable = pgTable("power_supply", {
|
|---|
| 47 | componentId: integer("component_id")
|
|---|
| 48 | .primaryKey()
|
|---|
| 49 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 50 | type: text("type").notNull(),
|
|---|
| 51 | wattage: numeric("wattage").notNull(),
|
|---|
| 52 | formFactor: text("form_factor").notNull(),
|
|---|
| 53 | });
|
|---|
| 54 |
|
|---|
| [1ebac59] | 55 | export const pcCasesTable = pgTable("pc_case", {
|
|---|
| [fdd776b] | 56 | componentId: integer("component_id")
|
|---|
| 57 | .primaryKey()
|
|---|
| 58 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 59 | coolerMaxHeight: numeric("cooler_max_height").notNull(),
|
|---|
| 60 | gpuMaxLength: numeric("gpu_max_length").notNull(),
|
|---|
| 61 | });
|
|---|
| 62 |
|
|---|
| 63 | // Case multi-values
|
|---|
| 64 | export const caseStorageFormFactorsTable = pgTable("case_storage_form_factors", {
|
|---|
| 65 | caseId: integer("case_id")
|
|---|
| 66 | .notNull()
|
|---|
| [1ebac59] | 67 | .references(() => pcCasesTable.componentId, {onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| [fdd776b] | 68 | formFactor: text("form_factor").notNull(),
|
|---|
| [b615094] | 69 | numSlots: integer("num_slots").notNull(),
|
|---|
| [fdd776b] | 70 | },
|
|---|
| 71 | (t) => ({
|
|---|
| 72 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 73 | }),
|
|---|
| 74 | );
|
|---|
| 75 |
|
|---|
| 76 | export const casePsFormFactorsTable = pgTable( "case_ps_form_factors", {
|
|---|
| 77 | caseId: integer("case_id")
|
|---|
| 78 | .notNull()
|
|---|
| [1ebac59] | 79 | .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| [fdd776b] | 80 | formFactor: text("form_factor").notNull(),
|
|---|
| 81 | },
|
|---|
| 82 | (t) => ({
|
|---|
| 83 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 84 | }),
|
|---|
| 85 | );
|
|---|
| 86 |
|
|---|
| 87 | export const caseMoboFormFactorsTable = pgTable("case_mobo_form_factors", {
|
|---|
| 88 | caseId: integer("case_id")
|
|---|
| 89 | .notNull()
|
|---|
| [1ebac59] | 90 | .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| [fdd776b] | 91 | formFactor: text("form_factor").notNull(),
|
|---|
| 92 | },
|
|---|
| 93 | (t) => ({
|
|---|
| 94 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 95 | }),
|
|---|
| 96 | );
|
|---|
| 97 |
|
|---|
| [1ebac59] | 98 | export const coolersTable = pgTable("cooler", {
|
|---|
| [fdd776b] | 99 | componentId: integer("component_id")
|
|---|
| 100 | .primaryKey()
|
|---|
| 101 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 102 | type: text("type").notNull(),
|
|---|
| 103 | height: numeric("height").notNull(),
|
|---|
| 104 | maxTdpSupported: numeric("max_tdp_supported").notNull(),
|
|---|
| 105 | });
|
|---|
| 106 |
|
|---|
| 107 | // Cooler multi-values
|
|---|
| 108 | export const coolerCPUSocketsTable = pgTable("cooler_cpu_sockets", {
|
|---|
| [b615094] | 109 | coolerId: integer("cooler_id")
|
|---|
| [fdd776b] | 110 | .notNull()
|
|---|
| [1ebac59] | 111 | .references(() => coolersTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| [fdd776b] | 112 | socket: text("socket").notNull(),
|
|---|
| 113 | },
|
|---|
| 114 | (t) => ({
|
|---|
| [b615094] | 115 | pk: primaryKey({ columns: [t.coolerId, t.socket] }),
|
|---|
| [fdd776b] | 116 | })
|
|---|
| 117 | );
|
|---|
| 118 |
|
|---|
| [1ebac59] | 119 | export const motherboardsTable = pgTable("motherboard", {
|
|---|
| [fdd776b] | 120 | componentId: integer("component_id")
|
|---|
| 121 | .primaryKey()
|
|---|
| 122 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 123 |
|
|---|
| 124 | socket: text("socket").notNull(),
|
|---|
| 125 | chipset: text("chipset").notNull(),
|
|---|
| 126 | formFactor: text("form_factor").notNull(),
|
|---|
| 127 | ramType: text("ram_type").notNull(),
|
|---|
| 128 | numRamSlots: integer("num_ram_slots").notNull(),
|
|---|
| 129 | maxRamCapacity: numeric("max_ram_capacity").notNull(),
|
|---|
| 130 | });
|
|---|
| 131 |
|
|---|
| 132 | export const storageTable = pgTable("storage", {
|
|---|
| 133 | componentId: integer("component_id")
|
|---|
| 134 | .primaryKey()
|
|---|
| 135 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 136 | type: text("type").notNull(),
|
|---|
| 137 | capacity: numeric("capacity").notNull(),
|
|---|
| 138 | formFactor: text("form_factor").notNull(),
|
|---|
| 139 | });
|
|---|
| 140 |
|
|---|
| 141 | // Other Components
|
|---|
| [1ebac59] | 142 | export const memoryCardsTable = pgTable("memory_card", {
|
|---|
| [fdd776b] | 143 | componentId: integer("component_id")
|
|---|
| 144 | .primaryKey()
|
|---|
| 145 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 146 | numSlots: integer("num_slots").notNull(),
|
|---|
| 147 | interface: text("interface").notNull(),
|
|---|
| 148 | });
|
|---|
| 149 |
|
|---|
| [1ebac59] | 150 | export const opticalDrivesTable = pgTable("optical_drive", {
|
|---|
| [fdd776b] | 151 | componentId: integer("component_id")
|
|---|
| 152 | .primaryKey()
|
|---|
| 153 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 154 | formFactor: text("form_factor").notNull(),
|
|---|
| 155 | type: text("type").notNull(),
|
|---|
| 156 | interface: text("interface").notNull(),
|
|---|
| 157 | writeSpeed: numeric("write_speed").notNull(),
|
|---|
| 158 | readSpeed: numeric("read_speed").notNull(),
|
|---|
| 159 | });
|
|---|
| 160 |
|
|---|
| [1ebac59] | 161 | export const soundCardsTable = pgTable("sound_card", {
|
|---|
| [fdd776b] | 162 | componentId: integer("component_id")
|
|---|
| 163 | .primaryKey()
|
|---|
| 164 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 165 | sampleRate: numeric("sample_rate").notNull(),
|
|---|
| 166 | bitDepth: numeric("bit_depth").notNull(),
|
|---|
| 167 | chipset: text("chipset").notNull(),
|
|---|
| 168 | interface: text("interface").notNull(),
|
|---|
| [1ebac59] | 169 | channel: text("channel").notNull(),
|
|---|
| [fdd776b] | 170 | });
|
|---|
| 171 |
|
|---|
| 172 | export const cablesTable = pgTable("cables", {
|
|---|
| 173 | componentId: integer("component_id")
|
|---|
| 174 | .primaryKey()
|
|---|
| 175 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 176 | lengthCm: numeric("length_cm").notNull(),
|
|---|
| 177 | type: text("type").notNull(),
|
|---|
| 178 | });
|
|---|
| 179 |
|
|---|
| [1ebac59] | 180 | export const networkAdaptersTable = pgTable("network_adapter", {
|
|---|
| [fdd776b] | 181 | componentId: integer("component_id")
|
|---|
| 182 | .primaryKey()
|
|---|
| 183 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 184 | wifiVersion: text("wifi_version").notNull(),
|
|---|
| 185 | interface: text("interface").notNull(),
|
|---|
| 186 | numAntennas: integer("num_antennas").notNull(),
|
|---|
| 187 | });
|
|---|
| 188 |
|
|---|
| [1ebac59] | 189 | export const networkCardsTable = pgTable("network_card", {
|
|---|
| [fdd776b] | 190 | componentId: integer("component_id")
|
|---|
| 191 | .primaryKey()
|
|---|
| 192 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 193 | numPorts: integer("num_ports").notNull(),
|
|---|
| 194 | speed: numeric("speed").notNull(),
|
|---|
| 195 | interface: text("interface").notNull(),
|
|---|
| 196 | });
|
|---|
| 197 |
|
|---|
| 198 | export type componentItem = typeof componentsTable.$inferSelect;
|
|---|
| 199 | export type componentInsert = typeof componentsTable.$inferInsert;
|
|---|
| 200 |
|
|---|
| 201 | export type cpuItem = typeof CPUTable.$inferSelect;
|
|---|
| 202 | export type cpuInsert = typeof CPUTable.$inferInsert;
|
|---|
| 203 |
|
|---|
| 204 | export type gpuItem = typeof GPUTable.$inferSelect;
|
|---|
| 205 | export type gpuInsert = typeof GPUTable.$inferInsert;
|
|---|
| 206 |
|
|---|
| 207 | export type memoryItem = typeof memoryTable.$inferSelect;
|
|---|
| 208 | export type memoryInsert = typeof memoryTable.$inferInsert;
|
|---|
| 209 |
|
|---|
| 210 | export type powerSupplyItem = typeof powerSupplyTable.$inferSelect;
|
|---|
| 211 | export type powerSupplyInsert = typeof powerSupplyTable.$inferInsert;
|
|---|
| 212 |
|
|---|
| [1ebac59] | 213 | export type caseItem = typeof pcCasesTable.$inferSelect;
|
|---|
| 214 | export type caseInsert = typeof pcCasesTable.$inferInsert;
|
|---|
| [fdd776b] | 215 |
|
|---|
| 216 | export type caseStorageFormFactorsItem = typeof caseStorageFormFactorsTable.$inferSelect;
|
|---|
| 217 | export type caseStorageFormFactorsInsert = typeof caseStorageFormFactorsTable.$inferInsert;
|
|---|
| 218 |
|
|---|
| 219 | export type casePsFormFactorsItem = typeof casePsFormFactorsTable.$inferSelect;
|
|---|
| 220 | export type casePsFormFactorsInsert = typeof casePsFormFactorsTable.$inferInsert;
|
|---|
| 221 |
|
|---|
| 222 | export type caseMoboFormFactorsItem = typeof caseMoboFormFactorsTable.$inferSelect;
|
|---|
| 223 | export type caseMoboFormFactorsInsert = typeof caseMoboFormFactorsTable.$inferInsert;
|
|---|
| 224 |
|
|---|
| [1ebac59] | 225 | export type coolerItem = typeof coolersTable.$inferSelect;
|
|---|
| 226 | export type coolerInsert = typeof coolersTable.$inferInsert;
|
|---|
| [fdd776b] | 227 |
|
|---|
| 228 | export type coolerCPUSocketsItem = typeof coolerCPUSocketsTable.$inferSelect;
|
|---|
| 229 | export type coolerCPUSocketsInsert = typeof coolerCPUSocketsTable.$inferInsert;
|
|---|
| 230 |
|
|---|
| [1ebac59] | 231 | export type motherboardItem = typeof motherboardsTable.$inferSelect;
|
|---|
| 232 | export type motherboardInsert = typeof motherboardsTable.$inferInsert;
|
|---|
| [fdd776b] | 233 |
|
|---|
| 234 | export type storageItem = typeof storageTable.$inferSelect;
|
|---|
| 235 | export type storageInsert = typeof storageTable.$inferInsert
|
|---|
| 236 |
|
|---|
| [1ebac59] | 237 | export type memoryCardItem = typeof memoryCardsTable.$inferSelect;
|
|---|
| 238 | export type memoryCardInsert = typeof memoryCardsTable.$inferInsert;
|
|---|
| [fdd776b] | 239 |
|
|---|
| [1ebac59] | 240 | export type opticalDriveItem = typeof opticalDrivesTable.$inferSelect;
|
|---|
| 241 | export type opticalDriveInsert = typeof opticalDrivesTable.$inferInsert;
|
|---|
| [fdd776b] | 242 |
|
|---|
| [1ebac59] | 243 | export type soundCardItem = typeof soundCardsTable.$inferSelect;
|
|---|
| 244 | export type soundCardInsert = typeof soundCardsTable.$inferInsert;
|
|---|
| [fdd776b] | 245 |
|
|---|
| 246 | export type cablesItem = typeof cablesTable.$inferSelect;
|
|---|
| 247 | export type cablesInsert = typeof cablesTable.$inferInsert;
|
|---|
| 248 |
|
|---|
| [1ebac59] | 249 | export type networkAdapterItem = typeof networkAdaptersTable.$inferSelect;
|
|---|
| 250 | export type networkAdapterInsert = typeof networkAdaptersTable.$inferInsert;
|
|---|
| [fdd776b] | 251 |
|
|---|
| [1ebac59] | 252 | export type networkCardItem = typeof networkCardsTable.$inferSelect;
|
|---|
| 253 | export type networkCardInsert = typeof networkCardsTable.$inferInsert;
|
|---|
| [fdd776b] | 254 |
|
|---|