| 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 |
|
|---|
| 55 | export const pcCaseTable = pgTable("pc_case", {
|
|---|
| 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()
|
|---|
| 67 | .references(() => pcCaseTable.componentId, {onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 68 | formFactor: text("form_factor").notNull(),
|
|---|
| 69 | },
|
|---|
| 70 | (t) => ({
|
|---|
| 71 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 72 | }),
|
|---|
| 73 | );
|
|---|
| 74 |
|
|---|
| 75 | export const casePsFormFactorsTable = pgTable( "case_ps_form_factors", {
|
|---|
| 76 | caseId: integer("case_id")
|
|---|
| 77 | .notNull()
|
|---|
| 78 | .references(() => pcCaseTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| 79 | formFactor: text("form_factor").notNull(),
|
|---|
| 80 | },
|
|---|
| 81 | (t) => ({
|
|---|
| 82 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 83 | }),
|
|---|
| 84 | );
|
|---|
| 85 |
|
|---|
| 86 | export const caseMoboFormFactorsTable = pgTable("case_mobo_form_factors", {
|
|---|
| 87 | caseId: integer("case_id")
|
|---|
| 88 | .notNull()
|
|---|
| 89 | .references(() => pcCaseTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| 90 | formFactor: text("form_factor").notNull(),
|
|---|
| 91 | },
|
|---|
| 92 | (t) => ({
|
|---|
| 93 | pk: primaryKey({ columns: [t.caseId, t.formFactor] }),
|
|---|
| 94 | }),
|
|---|
| 95 | );
|
|---|
| 96 |
|
|---|
| 97 | export const coolerTable = pgTable("cooler", {
|
|---|
| 98 | componentId: integer("component_id")
|
|---|
| 99 | .primaryKey()
|
|---|
| 100 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 101 | type: text("type").notNull(),
|
|---|
| 102 | height: numeric("height").notNull(),
|
|---|
| 103 | maxTdpSupported: numeric("max_tdp_supported").notNull(),
|
|---|
| 104 | });
|
|---|
| 105 |
|
|---|
| 106 | // Cooler multi-values
|
|---|
| 107 | export const coolerCPUSocketsTable = pgTable("cooler_cpu_sockets", {
|
|---|
| 108 | cooler_id: integer("cooler_id")
|
|---|
| 109 | .notNull()
|
|---|
| 110 | .references(() => coolerTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 111 | socket: text("socket").notNull(),
|
|---|
| 112 | },
|
|---|
| 113 | (t) => ({
|
|---|
| 114 | pk: primaryKey({ columns: [t.cooler_id, t.socket] }),
|
|---|
| 115 | })
|
|---|
| 116 | );
|
|---|
| 117 |
|
|---|
| 118 | export const motherboardTable = pgTable("motherboard", {
|
|---|
| 119 | componentId: integer("component_id")
|
|---|
| 120 | .primaryKey()
|
|---|
| 121 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 122 |
|
|---|
| 123 | socket: text("socket").notNull(),
|
|---|
| 124 | chipset: text("chipset").notNull(),
|
|---|
| 125 | formFactor: text("form_factor").notNull(),
|
|---|
| 126 | ramType: text("ram_type").notNull(),
|
|---|
| 127 | numRamSlots: integer("num_ram_slots").notNull(),
|
|---|
| 128 | maxRamCapacity: numeric("max_ram_capacity").notNull(),
|
|---|
| 129 | });
|
|---|
| 130 |
|
|---|
| 131 | export const storageTable = pgTable("storage", {
|
|---|
| 132 | componentId: integer("component_id")
|
|---|
| 133 | .primaryKey()
|
|---|
| 134 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 135 | type: text("type").notNull(),
|
|---|
| 136 | capacity: numeric("capacity").notNull(),
|
|---|
| 137 | formFactor: text("form_factor").notNull(),
|
|---|
| 138 | });
|
|---|
| 139 |
|
|---|
| 140 | // Other Components
|
|---|
| 141 | export const memoryCardTable = pgTable("memory_card", {
|
|---|
| 142 | componentId: integer("component_id")
|
|---|
| 143 | .primaryKey()
|
|---|
| 144 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 145 | numSlots: integer("num_slots").notNull(),
|
|---|
| 146 | interface: text("interface").notNull(),
|
|---|
| 147 | });
|
|---|
| 148 |
|
|---|
| 149 | export const opticalDriveTable = pgTable("optical_drive", {
|
|---|
| 150 | componentId: integer("component_id")
|
|---|
| 151 | .primaryKey()
|
|---|
| 152 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 153 | formFactor: text("form_factor").notNull(),
|
|---|
| 154 | type: text("type").notNull(),
|
|---|
| 155 | interface: text("interface").notNull(),
|
|---|
| 156 | writeSpeed: numeric("write_speed").notNull(),
|
|---|
| 157 | readSpeed: numeric("read_speed").notNull(),
|
|---|
| 158 | });
|
|---|
| 159 |
|
|---|
| 160 | export const soundCardTable = pgTable("sound_card", {
|
|---|
| 161 | componentId: integer("component_id")
|
|---|
| 162 | .primaryKey()
|
|---|
| 163 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 164 | sampleRate: numeric("sample_rate").notNull(),
|
|---|
| 165 | bitDepth: numeric("bit_depth").notNull(),
|
|---|
| 166 | chipset: text("chipset").notNull(),
|
|---|
| 167 | interface: text("interface").notNull(),
|
|---|
| 168 | });
|
|---|
| 169 |
|
|---|
| 170 | // SoundCard multi-values
|
|---|
| 171 | export const soundCardChannelsTable = pgTable("sound_card_channels", {
|
|---|
| 172 | soundCardId: integer("sound_card_id")
|
|---|
| 173 | .notNull()
|
|---|
| 174 | .references(() => soundCardTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 175 | channel: text("channel").notNull(),
|
|---|
| 176 | },
|
|---|
| 177 | (t) => ({
|
|---|
| 178 | pk: primaryKey({ columns: [t.soundCardId, t.channel] }),
|
|---|
| 179 | })
|
|---|
| 180 | );
|
|---|
| 181 |
|
|---|
| 182 | export const cablesTable = pgTable("cables", {
|
|---|
| 183 | componentId: integer("component_id")
|
|---|
| 184 | .primaryKey()
|
|---|
| 185 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 186 | lengthCm: numeric("length_cm").notNull(),
|
|---|
| 187 | type: text("type").notNull(),
|
|---|
| 188 | });
|
|---|
| 189 |
|
|---|
| 190 | export const networkAdapterTable = pgTable("network_adapter", {
|
|---|
| 191 | componentId: integer("component_id")
|
|---|
| 192 | .primaryKey()
|
|---|
| 193 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 194 | wifiVersion: text("wifi_version").notNull(),
|
|---|
| 195 | interface: text("interface").notNull(),
|
|---|
| 196 | numAntennas: integer("num_antennas").notNull(),
|
|---|
| 197 | });
|
|---|
| 198 |
|
|---|
| 199 | export const networkCardTable = pgTable("network_card", {
|
|---|
| 200 | componentId: integer("component_id")
|
|---|
| 201 | .primaryKey()
|
|---|
| 202 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 203 | numPorts: integer("num_ports").notNull(),
|
|---|
| 204 | speed: numeric("speed").notNull(),
|
|---|
| 205 | interface: text("interface").notNull(),
|
|---|
| 206 | });
|
|---|
| 207 |
|
|---|
| 208 | export type componentItem = typeof componentsTable.$inferSelect;
|
|---|
| 209 | export type componentInsert = typeof componentsTable.$inferInsert;
|
|---|
| 210 |
|
|---|
| 211 | export type cpuItem = typeof CPUTable.$inferSelect;
|
|---|
| 212 | export type cpuInsert = typeof CPUTable.$inferInsert;
|
|---|
| 213 |
|
|---|
| 214 | export type gpuItem = typeof GPUTable.$inferSelect;
|
|---|
| 215 | export type gpuInsert = typeof GPUTable.$inferInsert;
|
|---|
| 216 |
|
|---|
| 217 | export type memoryItem = typeof memoryTable.$inferSelect;
|
|---|
| 218 | export type memoryInsert = typeof memoryTable.$inferInsert;
|
|---|
| 219 |
|
|---|
| 220 | export type powerSupplyItem = typeof powerSupplyTable.$inferSelect;
|
|---|
| 221 | export type powerSupplyInsert = typeof powerSupplyTable.$inferInsert;
|
|---|
| 222 |
|
|---|
| 223 | export type caseItem = typeof pcCaseTable.$inferSelect;
|
|---|
| 224 | export type caseInsert = typeof pcCaseTable.$inferInsert;
|
|---|
| 225 |
|
|---|
| 226 | export type caseStorageFormFactorsItem = typeof caseStorageFormFactorsTable.$inferSelect;
|
|---|
| 227 | export type caseStorageFormFactorsInsert = typeof caseStorageFormFactorsTable.$inferInsert;
|
|---|
| 228 |
|
|---|
| 229 | export type casePsFormFactorsItem = typeof casePsFormFactorsTable.$inferSelect;
|
|---|
| 230 | export type casePsFormFactorsInsert = typeof casePsFormFactorsTable.$inferInsert;
|
|---|
| 231 |
|
|---|
| 232 | export type caseMoboFormFactorsItem = typeof caseMoboFormFactorsTable.$inferSelect;
|
|---|
| 233 | export type caseMoboFormFactorsInsert = typeof caseMoboFormFactorsTable.$inferInsert;
|
|---|
| 234 |
|
|---|
| 235 | export type coolerItem = typeof coolerTable.$inferSelect;
|
|---|
| 236 | export type coolerInsert = typeof coolerTable.$inferInsert;
|
|---|
| 237 |
|
|---|
| 238 | export type coolerCPUSocketsItem = typeof coolerCPUSocketsTable.$inferSelect;
|
|---|
| 239 | export type coolerCPUSocketsInsert = typeof coolerCPUSocketsTable.$inferInsert;
|
|---|
| 240 |
|
|---|
| 241 | export type motherboardItem = typeof motherboardTable.$inferSelect;
|
|---|
| 242 | export type motherboardInsert = typeof motherboardTable.$inferInsert;
|
|---|
| 243 |
|
|---|
| 244 | export type storageItem = typeof storageTable.$inferSelect;
|
|---|
| 245 | export type storageInsert = typeof storageTable.$inferInsert
|
|---|
| 246 |
|
|---|
| 247 | export type memoryCardItem = typeof memoryCardTable.$inferSelect;
|
|---|
| 248 | export type memoryCardInsert = typeof memoryCardTable.$inferInsert;
|
|---|
| 249 |
|
|---|
| 250 | export type opticalDriveItem = typeof opticalDriveTable.$inferSelect;
|
|---|
| 251 | export type opticalDriveInsert = typeof opticalDriveTable.$inferInsert;
|
|---|
| 252 |
|
|---|
| 253 | export type soundCardItem = typeof soundCardTable.$inferSelect;
|
|---|
| 254 | export type soundCardInsert = typeof soundCardTable.$inferInsert;
|
|---|
| 255 |
|
|---|
| 256 | export type soundCardChannelsItem = typeof soundCardChannelsTable.$inferSelect;
|
|---|
| 257 | export type soundCardChannelsInsert = typeof soundCardChannelsTable.$inferInsert;
|
|---|
| 258 |
|
|---|
| 259 | export type cablesItem = typeof cablesTable.$inferSelect;
|
|---|
| 260 | export type cablesInsert = typeof cablesTable.$inferInsert;
|
|---|
| 261 |
|
|---|
| 262 | export type networkAdapterItem = typeof networkAdapterTable.$inferSelect;
|
|---|
| 263 | export type networkAdapterInsert = typeof networkAdapterTable.$inferInsert;
|
|---|
| 264 |
|
|---|
| 265 | export type networkCardItem = typeof networkCardTable.$inferSelect;
|
|---|
| 266 | export type networkCardInsert = typeof networkCardTable.$inferInsert;
|
|---|
| 267 |
|
|---|