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