Ignore:
Timestamp:
12/20/25 00:55:47 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
b69759d
Parents:
c30935a
Message:

add schema and queries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • database/drizzle/schema/relations.ts

    rc30935a r1ebac59  
    77    memoryTable,
    88    powerSupplyTable,
    9     pcCaseTable,
     9    pcCasesTable,
    1010    caseStorageFormFactorsTable,
    1111    casePsFormFactorsTable,
    1212    caseMoboFormFactorsTable,
    13     coolerTable,
     13    coolersTable,
    1414    coolerCPUSocketsTable,
    15     motherboardTable,
     15    motherboardsTable,
    1616    storageTable,
    17     memoryCardTable,
    18     opticalDriveTable,
    19     soundCardTable,
    20     soundCardChannelsTable,
     17    memoryCardsTable,
     18    opticalDrivesTable,
     19    soundCardsTable,
    2120    cablesTable,
    22     networkAdapterTable,
    23     networkCardTable,
     21    networkAdaptersTable,
     22    networkCardsTable,
    2423
    2524} from "./components";
    2625
    2726import {
    28     buildTable,
    29     buildComponentTable,
    30     favoriteBuildTable,
    31     ratingBuildTable,
    32     reviewTable
     27    buildsTable,
     28    buildComponentsTable,
     29    favoriteBuildsTable,
     30    ratingBuildsTable,
     31    reviewsTable
    3332} from "./builds"
    3433
     
    4039
    4140export const usersRelations = relations(usersTable, ({ many, one }) => ({
    42     builds: many(buildTable),
    43     reviews: many(reviewTable),
    44     favorites: many(favoriteBuildTable),
    45     ratings: many(ratingBuildTable),
     41    builds: many(buildsTable),
     42    reviews: many(reviewsTable),
     43    favorites: many(favoriteBuildsTable),
     44    ratings: many(ratingBuildsTable),
    4645    suggestions: many(suggestionsTable),
    4746    adminProfile: one(adminsTable, {
     
    7069}));
    7170
    72 export const buildRelations = relations(buildTable, ({ one, many }) => ({
     71export const buildRelations = relations(buildsTable, ({ one, many }) => ({
    7372    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 }) => ({
     73        fields: [buildsTable.userId],
     74        references: [usersTable.id],
     75    }),
     76    buildComponents: many(buildComponentsTable),
     77    favorites: many(favoriteBuildsTable),
     78    ratings: many(ratingBuildsTable),
     79    reviews: many(reviewsTable),
     80}));
     81
     82export const buildComponentRelations = relations(buildComponentsTable, ({ one }) => ({
     83    build: one(buildsTable, {
     84        fields: [buildComponentsTable.buildId],
     85        references: [buildsTable.id],
     86    }),
     87    component: one(componentsTable, {
     88        fields: [buildComponentsTable.componentId],
     89        references: [componentsTable.id],
     90    }),
     91}));
     92
     93export const favoriteBuildRelations = relations(favoriteBuildsTable, ({ one }) => ({
    9594    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 }) => ({
     95        fields: [favoriteBuildsTable.userId],
     96        references: [usersTable.id],
     97    }),
     98    build: one(buildsTable, {
     99        fields: [favoriteBuildsTable.buildId],
     100        references: [buildsTable.id],
     101    }),
     102}));
     103
     104export const ratingBuildRelations = relations(ratingBuildsTable, ({ one }) => ({
    106105    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 }) => ({
     106        fields: [ratingBuildsTable.userId],
     107        references: [usersTable.id],
     108    }),
     109    build: one(buildsTable, {
     110        fields: [ratingBuildsTable.buildId],
     111        references: [buildsTable.id],
     112    }),
     113}));
     114
     115export const reviewRelations = relations(reviewsTable, ({ one }) => ({
    117116    author: one(usersTable, {
    118         fields: [reviewTable.userId],
    119         references: [usersTable.id],
    120     }),
    121     build: one(buildTable, {
    122         fields: [reviewTable.buildId],
    123         references: [buildTable.id],
     117        fields: [reviewsTable.userId],
     118        references: [usersTable.id],
     119    }),
     120    build: one(buildsTable, {
     121        fields: [reviewsTable.buildId],
     122        references: [buildsTable.id],
    124123    }),
    125124}));
    126125
    127126export const componentsRelations = relations(componentsTable, ({ many, one }) => ({
    128     buildComponents: many(buildComponentTable),
     127    buildComponents: many(buildComponentsTable),
    129128
    130129    cpu: one(CPUTable, {
     
    144143        references: [powerSupplyTable.componentId]
    145144    }),
    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]
     145    pcCase: one(pcCasesTable, {
     146        fields: [componentsTable.id],
     147        references: [pcCasesTable.componentId]
     148    }),
     149    cooler: one(coolersTable, {
     150        fields: [componentsTable.id],
     151        references: [coolersTable.componentId]
     152    }),
     153    motherboard: one(motherboardsTable, {
     154        fields: [componentsTable.id],
     155        references: [motherboardsTable.componentId]
    157156    }),
    158157    storage: one(storageTable, {
     
    160159        references: [storageTable.componentId]
    161160    }),
    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]
     161    memoryCard: one(memoryCardsTable, {
     162        fields: [componentsTable.id],
     163        references: [memoryCardsTable.componentId]
     164    }),
     165    opticalDrive: one(opticalDrivesTable, {
     166        fields: [componentsTable.id],
     167        references: [opticalDrivesTable.componentId]
     168    }),
     169    soundCard: one(soundCardsTable, {
     170        fields: [componentsTable.id],
     171        references: [soundCardsTable.componentId]
    173172    }),
    174173    cables: one(cablesTable, {
     
    176175        references: [cablesTable.componentId]
    177176    }),
    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]
     177    networkAdapter: one(networkAdaptersTable, {
     178        fields: [componentsTable.id],
     179        references: [networkAdaptersTable.componentId]
     180    }),
     181    networkCard: one(networkCardsTable, {
     182        fields: [componentsTable.id],
     183        references: [networkCardsTable.componentId]
    185184    }),
    186185}));
     
    214213}));
    215214
    216 export const motherboardRelations = relations(motherboardTable, ({ one }) => ({
    217     component: one(componentsTable, {
    218         fields: [motherboardTable.componentId],
     215export const motherboardRelations = relations(motherboardsTable, ({ one }) => ({
     216    component: one(componentsTable, {
     217        fields: [motherboardsTable.componentId],
    219218        references: [componentsTable.id],
    220219    }),
     
    228227}));
    229228
    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],
     229export const memoryCardRelations = relations(memoryCardsTable, ({ one }) => ({
     230    component: one(componentsTable, {
     231        fields: [memoryCardsTable.componentId],
     232        references: [componentsTable.id],
     233    }),
     234}));
     235
     236export const opticalDriveRelations = relations(opticalDrivesTable, ({ one }) => ({
     237    component: one(componentsTable, {
     238        fields: [opticalDrivesTable.componentId],
    240239        references: [componentsTable.id],
    241240    }),
     
    249248}));
    250249
    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],
     250export const networkAdapterRelations = relations(networkAdaptersTable, ({ one }) => ({
     251    component: one(componentsTable, {
     252        fields: [networkAdaptersTable.componentId],
     253        references: [componentsTable.id],
     254    }),
     255}));
     256
     257export const networkCardRelations = relations(networkCardsTable, ({ one }) => ({
     258    component: one(componentsTable, {
     259        fields: [networkCardsTable.componentId],
     260        references: [componentsTable.id],
     261    }),
     262}));
     263
     264export const pcCaseRelations = relations(pcCasesTable, ({ one, many }) => ({
     265    component: one(componentsTable, {
     266        fields: [pcCasesTable.componentId],
    268267        references: [componentsTable.id],
    269268    }),
     
    274273
    275274export const caseStorageFormFactorsRelations = relations(caseStorageFormFactorsTable, ({ one }) => ({
    276     pcCase: one(pcCaseTable, {
     275    pcCase: one(pcCasesTable, {
    277276        fields: [caseStorageFormFactorsTable.caseId],
    278         references: [pcCaseTable.componentId],
     277        references: [pcCasesTable.componentId],
    279278    }),
    280279}));
    281280
    282281export const casePsFormFactorsRelations = relations(casePsFormFactorsTable, ({ one }) => ({
    283     pcCase: one(pcCaseTable, {
     282    pcCase: one(pcCasesTable, {
    284283        fields: [casePsFormFactorsTable.caseId],
    285         references: [pcCaseTable.componentId],
     284        references: [pcCasesTable.componentId],
    286285    }),
    287286}));
    288287
    289288export const caseMoboFormFactorsRelations = relations(caseMoboFormFactorsTable, ({ one }) => ({
    290     pcCase: one(pcCaseTable, {
     289    pcCase: one(pcCasesTable, {
    291290        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],
     291        references: [pcCasesTable.componentId],
     292    }),
     293}));
     294
     295export const coolerRelations = relations(coolersTable, ({ one, many }) => ({
     296    component: one(componentsTable, {
     297        fields: [coolersTable.componentId],
    299298        references: [componentsTable.id],
    300299    }),
     
    303302
    304303export const coolerCpuSocketsRelations = relations(coolerCPUSocketsTable, ({ one }) => ({
    305     cooler: one(coolerTable, {
     304    cooler: one(coolersTable, {
    306305        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 }));
     306        references: [coolersTable.componentId],
     307    }),
     308}));
     309
     310export const soundCardRelations = relations(soundCardsTable, ({ one, many }) => ({
     311    component: one(componentsTable, {
     312        fields: [soundCardsTable.componentId],
     313        references: [componentsTable.id],
     314    }),
     315}));
Note: See TracChangeset for help on using the changeset viewer.