barry
barry
Explore posts from servers
DTDrizzle Team
Created by barry on 11/30/2023 in #help
drizzle + postgres + express + ts, errors
realized i needed body parser, was lazy, used headers, main focus wasnt there 🤷
7 replies
DTDrizzle Team
Created by barry on 11/30/2023 in #help
drizzle + postgres + express + ts, errors
ahhh thx
7 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
oh wait im a dumb dumb i was using the relation definition instead of the table for the many relation input
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
The error is on the one to many relations between both user and calendar with the junction table.
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
The junction table looks like this
export const calendar_participant = pgTable('calendar_participant', {
id: serial('id').primaryKey(),
calendar_id: serial('calendar_id').notNull(),
user_id: serial('user_id').notNull(),
});

export const calendar_to_user_relations = relations(
calendar_participant,
({ one }) => ({
calendar: one(calendar, {
fields: [calendar_participant.calendar_id],
references: [calendar.id],
}),
user: one(user, {
fields: [calendar_participant.user_id],
references: [user.id],
}),
}),
);
export const calendar_participant = pgTable('calendar_participant', {
id: serial('id').primaryKey(),
calendar_id: serial('calendar_id').notNull(),
user_id: serial('user_id').notNull(),
});

export const calendar_to_user_relations = relations(
calendar_participant,
({ one }) => ({
calendar: one(calendar, {
fields: [calendar_participant.calendar_id],
references: [calendar.id],
}),
user: one(user, {
fields: [calendar_participant.user_id],
references: [user.id],
}),
}),
);
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
Lemm walk through it, might make sense
export const user = pgTable(
'user',
{
id: serial('id').primaryKey(),
username: varchar('username', { length: 255 }).unique(),
password_hash: varchar('password_hash', { length: 255 }).notNull(),
password_salt: varchar('password_salt', { length: 255 }).notNull(),
name: varchar('name', { length: 255 }),
},
(table) => {
return {
usernameIdx: uniqueIndex('username_idx').on(table.username),
idIdx: uniqueIndex('id_idx').on(table.id),
};
},
);
export const user = pgTable(
'user',
{
id: serial('id').primaryKey(),
username: varchar('username', { length: 255 }).unique(),
password_hash: varchar('password_hash', { length: 255 }).notNull(),
password_salt: varchar('password_salt', { length: 255 }).notNull(),
name: varchar('name', { length: 255 }),
},
(table) => {
return {
usernameIdx: uniqueIndex('username_idx').on(table.username),
idIdx: uniqueIndex('id_idx').on(table.id),
};
},
);
We've got a user storing all this, which has a one to many relationship with both the session table and calendar table like this
export const user_relations = relations(user, ({ many }) => ({
session: many(session),
calendar: many(calendar_to_user_relations),
}));
export const user_relations = relations(user, ({ many }) => ({
session: many(session),
calendar: many(calendar_to_user_relations),
}));
calendar_to_user_relations is a junction/join table Session is irrelevant to the error so let's skip to the calendar table
export const calendar = pgTable(
'calendar',
{
id: serial('id').primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
description: varchar('description', { length: 255 }),
time_of_creation: timestamp('creation_date').defaultNow(),
author_id: serial('author_id').notNull(),
},
(table) => {
return {
nameIdx: uniqueIndex('name_idx').on(table.name),
};
},
);
export const calendar = pgTable(
'calendar',
{
id: serial('id').primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
description: varchar('description', { length: 255 }),
time_of_creation: timestamp('creation_date').defaultNow(),
author_id: serial('author_id').notNull(),
},
(table) => {
return {
nameIdx: uniqueIndex('name_idx').on(table.name),
};
},
);
And it's one to many relationship with the junction table
export const calendar_relations = relations(calendar, ({ many }) => ({
calendar_to_user_relations: many(calendar_to_user_relations),
}));
export const calendar_relations = relations(calendar, ({ many }) => ({
calendar_to_user_relations: many(calendar_to_user_relations),
}));
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
But i'm not sure how to structure that last relation
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
One calendar can also have many participants
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
One calendar can have one author.
9 replies
DTDrizzle Team
Created by barry on 8/14/2023 in #help
How should I set this up?
So the idea is one user can create many calendars.
9 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
ah my bad
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
npm i drizzle-kit@cjs
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
what about drizzle-kit@cjs
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
you sol
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
oh well im out of ideas now
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
what if u get rid of the await then lol
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
Might work?
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
const { pgTable, serial, text, varchar } = await import("drizzle-orm/pg-core")
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
so you need to be doing require? no?
67 replies
DTDrizzle Team
Created by Zamiel on 8/12/2023 in #help
Does Drizzle ORM support CommonJS (CJS)?
No description
67 replies