Thogn
Thogn
Explore posts from servers
DTDrizzle Team
Created by Thogn on 1/16/2024 in #help
insert row, got values back, but there's not data stored on the db
No description
8 replies
DTDrizzle Team
Created by Thogn on 1/15/2024 in #help
prepared statement "s3843" does not exist
No description
1 replies
DTDrizzle Team
Created by Thogn on 10/26/2023 in #help
How to define schemas for friendship table
Just wondering whether or not i should define friendshipsRelations table. Relation: A user can have many friends
export const usersRelations = relations(users, ({ many }) => ({
friendships: many(friendships),
}));

// Friends table
export const friendships = mysqlTable(
'friends',
{
userId: int('user_id').notNull(),
friendId: int('friend_id').notNull(),
},
(t) => {
return {
pk: primaryKey(t.userId, t.friendId),
};
},
);
// Define relationships
export const friendshipsRelations = relations(friendships, ({ one }) => ({
user1: one(users, {
fields: [friendships.userId],
references: [users.id],
}),
user2: one(users, {
fields: [friendships.friendId],
references: [users.id],
}),
}));
export const usersRelations = relations(users, ({ many }) => ({
friendships: many(friendships),
}));

// Friends table
export const friendships = mysqlTable(
'friends',
{
userId: int('user_id').notNull(),
friendId: int('friend_id').notNull(),
},
(t) => {
return {
pk: primaryKey(t.userId, t.friendId),
};
},
);
// Define relationships
export const friendshipsRelations = relations(friendships, ({ one }) => ({
user1: one(users, {
fields: [friendships.userId],
references: [users.id],
}),
user2: one(users, {
fields: [friendships.friendId],
references: [users.id],
}),
}));
1 replies
DTDrizzle Team
Created by Thogn on 9/27/2023 in #help
how to set default null to an int column
I want the parentId to have the default Null, how to do that
export const comments = mysqlTable(
'comments',
{
id: serial('id').primaryKey(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
});
export const comments = mysqlTable(
'comments',
{
id: serial('id').primaryKey(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
});
9 replies
DTDrizzle Team
Created by Thogn on 9/22/2023 in #help
many-to-may relation
How do i define relation like a post probably has many comments that nested, for example a person can reply to other person's comment,
export const comments = mysqlTable(
'comments',{
id: serial('id').primaryKey(),
postId: int('post_id'),
comment: text('content').notNull(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
likes: int('likes').default(0),
},

);
export const comments = mysqlTable(
'comments',{
id: serial('id').primaryKey(),
postId: int('post_id'),
comment: text('content').notNull(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
likes: int('likes').default(0),
},

);
5 replies