| [fdd776b] | 1 | import { relations } from "drizzle-orm";
|
|---|
| 2 |
|
|---|
| 3 | import {
|
|---|
| 4 | componentsTable,
|
|---|
| 5 | CPUTable,
|
|---|
| 6 | GPUTable,
|
|---|
| 7 | memoryTable,
|
|---|
| 8 | powerSupplyTable,
|
|---|
| 9 | pcCaseTable,
|
|---|
| 10 | caseStorageFormFactorsTable,
|
|---|
| 11 | casePsFormFactorsTable,
|
|---|
| 12 | caseMoboFormFactorsTable,
|
|---|
| 13 | coolerTable,
|
|---|
| 14 | coolerCPUSocketsTable,
|
|---|
| 15 | motherboardTable,
|
|---|
| 16 | storageTable,
|
|---|
| 17 | memoryCardTable,
|
|---|
| 18 | opticalDriveTable,
|
|---|
| 19 | soundCardTable,
|
|---|
| 20 | soundCardChannelsTable,
|
|---|
| 21 | cablesTable,
|
|---|
| 22 | networkAdapterTable,
|
|---|
| 23 | networkCardTable,
|
|---|
| 24 |
|
|---|
| 25 | } from "./components";
|
|---|
| 26 |
|
|---|
| 27 | import {
|
|---|
| 28 | buildTable,
|
|---|
| 29 | buildComponentTable,
|
|---|
| 30 | favoriteBuildTable,
|
|---|
| 31 | ratingBuildTable,
|
|---|
| 32 | reviewTable
|
|---|
| 33 | } from "./builds"
|
|---|
| 34 |
|
|---|
| 35 | import {
|
|---|
| 36 | usersTable,
|
|---|
| 37 | adminsTable,
|
|---|
| 38 | suggestionsTable
|
|---|
| 39 | } from "./users";
|
|---|
| 40 |
|
|---|
| 41 | export const usersRelations = relations(usersTable, ({ many, one }) => ({
|
|---|
| 42 | builds: many(buildTable),
|
|---|
| 43 | reviews: many(reviewTable),
|
|---|
| 44 | favorites: many(favoriteBuildTable),
|
|---|
| 45 | ratings: many(ratingBuildTable),
|
|---|
| 46 | suggestions: many(suggestionsTable),
|
|---|
| 47 | adminProfile: one(adminsTable, {
|
|---|
| 48 | fields: [usersTable.id],
|
|---|
| 49 | references: [adminsTable.userId],
|
|---|
| 50 | })
|
|---|
| 51 | }));
|
|---|
| 52 |
|
|---|
| 53 | export const adminsRelations = relations(adminsTable, ({ one, many }) => ({
|
|---|
| 54 | user: one(usersTable, {
|
|---|
| 55 | fields: [adminsTable.userId],
|
|---|
| 56 | references: [usersTable.id],
|
|---|
| 57 | }),
|
|---|
| 58 | moderatedSuggestions: many(suggestionsTable),
|
|---|
| 59 | }));
|
|---|
| 60 |
|
|---|
| 61 | export const suggestionsRelations = relations(suggestionsTable, ({ one }) => ({
|
|---|
| 62 | author: one(usersTable, {
|
|---|
| 63 | fields: [suggestionsTable.userId],
|
|---|
| 64 | references: [usersTable.id],
|
|---|
| 65 | }),
|
|---|
| 66 | moderator: one(adminsTable, {
|
|---|
| 67 | fields: [suggestionsTable.adminId],
|
|---|
| 68 | references: [adminsTable.userId],
|
|---|
| 69 | }),
|
|---|
| 70 | }));
|
|---|
| 71 |
|
|---|
| 72 | export const buildRelations = relations(buildTable, ({ one, many }) => ({
|
|---|
| 73 | owner: one(usersTable, {
|
|---|
| 74 | fields: [buildTable.userId],
|
|---|
| 75 | references: [usersTable.id],
|
|---|
| 76 | }),
|
|---|
| 77 | buildComponents: many(buildComponentTable),
|
|---|
| 78 | favorites: many(favoriteBuildTable),
|
|---|
| 79 | ratings: many(ratingBuildTable),
|
|---|
| 80 | reviews: many(reviewTable),
|
|---|
| 81 | }));
|
|---|
| 82 |
|
|---|
| 83 | export const buildComponentRelations = relations(buildComponentTable, ({ one }) => ({
|
|---|
| 84 | build: one(buildTable, {
|
|---|
| 85 | fields: [buildComponentTable.buildId],
|
|---|
| 86 | references: [buildTable.id],
|
|---|
| 87 | }),
|
|---|
| 88 | component: one(componentsTable, {
|
|---|
| 89 | fields: [buildComponentTable.componentId],
|
|---|
| 90 | references: [componentsTable.id],
|
|---|
| 91 | }),
|
|---|
| 92 | }));
|
|---|
| 93 |
|
|---|
| 94 | export const favoriteBuildRelations = relations(favoriteBuildTable, ({ one }) => ({
|
|---|
| 95 | user: one(usersTable, {
|
|---|
| 96 | fields: [favoriteBuildTable.userId],
|
|---|
| 97 | references: [usersTable.id],
|
|---|
| 98 | }),
|
|---|
| 99 | build: one(buildTable, {
|
|---|
| 100 | fields: [favoriteBuildTable.buildId],
|
|---|
| 101 | references: [buildTable.id],
|
|---|
| 102 | }),
|
|---|
| 103 | }));
|
|---|
| 104 |
|
|---|
| 105 | export const ratingBuildRelations = relations(ratingBuildTable, ({ one }) => ({
|
|---|
| 106 | user: one(usersTable, {
|
|---|
| 107 | fields: [ratingBuildTable.userId],
|
|---|
| 108 | references: [usersTable.id],
|
|---|
| 109 | }),
|
|---|
| 110 | build: one(buildTable, {
|
|---|
| 111 | fields: [ratingBuildTable.buildId],
|
|---|
| 112 | references: [buildTable.id],
|
|---|
| 113 | }),
|
|---|
| 114 | }));
|
|---|
| 115 |
|
|---|
| 116 | export const reviewRelations = relations(reviewTable, ({ one }) => ({
|
|---|
| 117 | author: one(usersTable, {
|
|---|
| 118 | fields: [reviewTable.userId],
|
|---|
| 119 | references: [usersTable.id],
|
|---|
| 120 | }),
|
|---|
| 121 | build: one(buildTable, {
|
|---|
| 122 | fields: [reviewTable.buildId],
|
|---|
| 123 | references: [buildTable.id],
|
|---|
| 124 | }),
|
|---|
| 125 | }));
|
|---|
| 126 |
|
|---|
| 127 | export const componentsRelations = relations(componentsTable, ({ many, one }) => ({
|
|---|
| 128 | buildComponents: many(buildComponentTable),
|
|---|
| 129 |
|
|---|
| 130 | cpu: one(CPUTable, {
|
|---|
| 131 | fields: [componentsTable.id],
|
|---|
| 132 | references: [CPUTable.componentId]
|
|---|
| 133 | }),
|
|---|
| 134 | gpu: one(GPUTable, {
|
|---|
| 135 | fields: [componentsTable.id],
|
|---|
| 136 | references: [GPUTable.componentId]
|
|---|
| 137 | }),
|
|---|
| 138 | memory: one(memoryTable, {
|
|---|
| 139 | fields: [componentsTable.id],
|
|---|
| 140 | references: [memoryTable.componentId]
|
|---|
| 141 | }),
|
|---|
| 142 | powerSupply: one(powerSupplyTable, {
|
|---|
| 143 | fields: [componentsTable.id],
|
|---|
| 144 | references: [powerSupplyTable.componentId]
|
|---|
| 145 | }),
|
|---|
| 146 | pcCase: one(pcCaseTable, {
|
|---|
| 147 | fields: [componentsTable.id],
|
|---|
| 148 | references: [pcCaseTable.componentId]
|
|---|
| 149 | }),
|
|---|
| 150 | cooler: one(coolerTable, {
|
|---|
| 151 | fields: [componentsTable.id],
|
|---|
| 152 | references: [coolerTable.componentId]
|
|---|
| 153 | }),
|
|---|
| 154 | motherboard: one(motherboardTable, {
|
|---|
| 155 | fields: [componentsTable.id],
|
|---|
| 156 | references: [motherboardTable.componentId]
|
|---|
| 157 | }),
|
|---|
| 158 | storage: one(storageTable, {
|
|---|
| 159 | fields: [componentsTable.id],
|
|---|
| 160 | references: [storageTable.componentId]
|
|---|
| 161 | }),
|
|---|
| 162 | memoryCard: one(memoryCardTable, {
|
|---|
| 163 | fields: [componentsTable.id],
|
|---|
| 164 | references: [memoryCardTable.componentId]
|
|---|
| 165 | }),
|
|---|
| 166 | opticalDrive: one(opticalDriveTable, {
|
|---|
| 167 | fields: [componentsTable.id],
|
|---|
| 168 | references: [opticalDriveTable.componentId]
|
|---|
| 169 | }),
|
|---|
| 170 | soundCard: one(soundCardTable, {
|
|---|
| 171 | fields: [componentsTable.id],
|
|---|
| 172 | references: [soundCardTable.componentId]
|
|---|
| 173 | }),
|
|---|
| 174 | cables: one(cablesTable, {
|
|---|
| 175 | fields: [componentsTable.id],
|
|---|
| 176 | references: [cablesTable.componentId]
|
|---|
| 177 | }),
|
|---|
| 178 | networkAdapter: one(networkAdapterTable, {
|
|---|
| 179 | fields: [componentsTable.id],
|
|---|
| 180 | references: [networkAdapterTable.componentId]
|
|---|
| 181 | }),
|
|---|
| 182 | networkCard: one(networkCardTable, {
|
|---|
| 183 | fields: [componentsTable.id],
|
|---|
| 184 | references: [networkCardTable.componentId]
|
|---|
| 185 | }),
|
|---|
| 186 | }));
|
|---|
| 187 |
|
|---|
| 188 | export const cpuRelations = relations(CPUTable, ({ one }) => ({
|
|---|
| 189 | component: one(componentsTable, {
|
|---|
| 190 | fields: [CPUTable.componentId],
|
|---|
| 191 | references: [componentsTable.id],
|
|---|
| 192 | }),
|
|---|
| 193 | }));
|
|---|
| 194 |
|
|---|
| 195 | export const gpuRelations = relations(GPUTable, ({ one }) => ({
|
|---|
| 196 | component: one(componentsTable, {
|
|---|
| 197 | fields: [GPUTable.componentId],
|
|---|
| 198 | references: [componentsTable.id],
|
|---|
| 199 | }),
|
|---|
| 200 | }));
|
|---|
| 201 |
|
|---|
| 202 | export const memoryRelations = relations(memoryTable, ({ one }) => ({
|
|---|
| 203 | component: one(componentsTable, {
|
|---|
| 204 | fields: [memoryTable.componentId],
|
|---|
| 205 | references: [componentsTable.id],
|
|---|
| 206 | }),
|
|---|
| 207 | }));
|
|---|
| 208 |
|
|---|
| 209 | export const powerSupplyRelations = relations(powerSupplyTable, ({ one }) => ({
|
|---|
| 210 | component: one(componentsTable, {
|
|---|
| 211 | fields: [powerSupplyTable.componentId],
|
|---|
| 212 | references: [componentsTable.id],
|
|---|
| 213 | }),
|
|---|
| 214 | }));
|
|---|
| 215 |
|
|---|
| 216 | export const motherboardRelations = relations(motherboardTable, ({ one }) => ({
|
|---|
| 217 | component: one(componentsTable, {
|
|---|
| 218 | fields: [motherboardTable.componentId],
|
|---|
| 219 | references: [componentsTable.id],
|
|---|
| 220 | }),
|
|---|
| 221 | }));
|
|---|
| 222 |
|
|---|
| 223 | export const storageRelations = relations(storageTable, ({ one }) => ({
|
|---|
| 224 | component: one(componentsTable, {
|
|---|
| 225 | fields: [storageTable.componentId],
|
|---|
| 226 | references: [componentsTable.id],
|
|---|
| 227 | }),
|
|---|
| 228 | }));
|
|---|
| 229 |
|
|---|
| 230 | export const memoryCardRelations = relations(memoryCardTable, ({ one }) => ({
|
|---|
| 231 | component: one(componentsTable, {
|
|---|
| 232 | fields: [memoryCardTable.componentId],
|
|---|
| 233 | references: [componentsTable.id],
|
|---|
| 234 | }),
|
|---|
| 235 | }));
|
|---|
| 236 |
|
|---|
| 237 | export const opticalDriveRelations = relations(opticalDriveTable, ({ one }) => ({
|
|---|
| 238 | component: one(componentsTable, {
|
|---|
| 239 | fields: [opticalDriveTable.componentId],
|
|---|
| 240 | references: [componentsTable.id],
|
|---|
| 241 | }),
|
|---|
| 242 | }));
|
|---|
| 243 |
|
|---|
| 244 | export const cablesRelations = relations(cablesTable, ({ one }) => ({
|
|---|
| 245 | component: one(componentsTable, {
|
|---|
| 246 | fields: [cablesTable.componentId],
|
|---|
| 247 | references: [componentsTable.id],
|
|---|
| 248 | }),
|
|---|
| 249 | }));
|
|---|
| 250 |
|
|---|
| 251 | export const networkAdapterRelations = relations(networkAdapterTable, ({ one }) => ({
|
|---|
| 252 | component: one(componentsTable, {
|
|---|
| 253 | fields: [networkAdapterTable.componentId],
|
|---|
| 254 | references: [componentsTable.id],
|
|---|
| 255 | }),
|
|---|
| 256 | }));
|
|---|
| 257 |
|
|---|
| 258 | export const networkCardRelations = relations(networkCardTable, ({ one }) => ({
|
|---|
| 259 | component: one(componentsTable, {
|
|---|
| 260 | fields: [networkCardTable.componentId],
|
|---|
| 261 | references: [componentsTable.id],
|
|---|
| 262 | }),
|
|---|
| 263 | }));
|
|---|
| 264 |
|
|---|
| 265 | export const pcCaseRelations = relations(pcCaseTable, ({ one, many }) => ({
|
|---|
| 266 | component: one(componentsTable, {
|
|---|
| 267 | fields: [pcCaseTable.componentId],
|
|---|
| 268 | references: [componentsTable.id],
|
|---|
| 269 | }),
|
|---|
| 270 | storageFormFactors: many(caseStorageFormFactorsTable),
|
|---|
| 271 | psFormFactors: many(casePsFormFactorsTable),
|
|---|
| 272 | moboFormFactors: many(caseMoboFormFactorsTable),
|
|---|
| 273 | }));
|
|---|
| 274 |
|
|---|
| 275 | export const caseStorageFormFactorsRelations = relations(caseStorageFormFactorsTable, ({ one }) => ({
|
|---|
| 276 | pcCase: one(pcCaseTable, {
|
|---|
| 277 | fields: [caseStorageFormFactorsTable.caseId],
|
|---|
| 278 | references: [pcCaseTable.componentId],
|
|---|
| 279 | }),
|
|---|
| 280 | }));
|
|---|
| 281 |
|
|---|
| 282 | export const casePsFormFactorsRelations = relations(casePsFormFactorsTable, ({ one }) => ({
|
|---|
| 283 | pcCase: one(pcCaseTable, {
|
|---|
| 284 | fields: [casePsFormFactorsTable.caseId],
|
|---|
| 285 | references: [pcCaseTable.componentId],
|
|---|
| 286 | }),
|
|---|
| 287 | }));
|
|---|
| 288 |
|
|---|
| 289 | export const caseMoboFormFactorsRelations = relations(caseMoboFormFactorsTable, ({ one }) => ({
|
|---|
| 290 | pcCase: one(pcCaseTable, {
|
|---|
| 291 | fields: [caseMoboFormFactorsTable.caseId],
|
|---|
| 292 | references: [pcCaseTable.componentId],
|
|---|
| 293 | }),
|
|---|
| 294 | }));
|
|---|
| 295 |
|
|---|
| 296 | export const coolerRelations = relations(coolerTable, ({ one, many }) => ({
|
|---|
| 297 | component: one(componentsTable, {
|
|---|
| 298 | fields: [coolerTable.componentId],
|
|---|
| 299 | references: [componentsTable.id],
|
|---|
| 300 | }),
|
|---|
| 301 | cpuSockets: many(coolerCPUSocketsTable),
|
|---|
| 302 | }));
|
|---|
| 303 |
|
|---|
| 304 | export const coolerCpuSocketsRelations = relations(coolerCPUSocketsTable, ({ one }) => ({
|
|---|
| 305 | cooler: one(coolerTable, {
|
|---|
| 306 | fields: [coolerCPUSocketsTable.cooler_id],
|
|---|
| 307 | references: [coolerTable.componentId],
|
|---|
| 308 | }),
|
|---|
| 309 | }));
|
|---|
| 310 |
|
|---|
| 311 | export const soundCardRelations = relations(soundCardTable, ({ one, many }) => ({
|
|---|
| 312 | component: one(componentsTable, {
|
|---|
| 313 | fields: [soundCardTable.componentId],
|
|---|
| 314 | references: [componentsTable.id],
|
|---|
| 315 | }),
|
|---|
| 316 | channels: many(soundCardChannelsTable),
|
|---|
| 317 | }));
|
|---|
| 318 |
|
|---|
| 319 | export const soundCardChannelsRelations = relations(soundCardChannelsTable, ({ one }) => ({
|
|---|
| 320 | soundCard: one(soundCardTable, {
|
|---|
| 321 | fields: [soundCardChannelsTable.soundCardId],
|
|---|
| 322 | references: [soundCardTable.componentId],
|
|---|
| 323 | }),
|
|---|
| 324 | })); |
|---|