wailroth
wailroth
Explore posts from servers
DTDrizzle Team
Created by wailroth on 10/22/2023 in #help
Schema to type
Hey guys, how do you make a schema item as a static type ? for example, this thing:
export const orderItems = pgTable("orderItem", {
product_id: serial("product_id").notNull(),
order_id: serial("order_id").notNull(),
quantity: integer("quantity")

},
(orderItems) => ({
compoundKey: primaryKey(orderItems.product_id, orderItems.order_id),
}
))
export const orderItems = pgTable("orderItem", {
product_id: serial("product_id").notNull(),
order_id: serial("order_id").notNull(),
quantity: integer("quantity")

},
(orderItems) => ({
compoundKey: primaryKey(orderItems.product_id, orderItems.order_id),
}
))
as
{
productId: number,
order_id: number,
quantity: number
}
{
productId: number,
order_id: number,
quantity: number
}
24 replies
DTDrizzle Team
Created by wailroth on 10/12/2023 in #help
Add even when object is null?
Hi guys, I have some issues with my schema:
export const userItems = pgTable("userItem", {
product_id: serial("product_id").notNull(),
user_id: text("user_id").notNull(),
quantity: integer("quantity")
},
(userItems) => ({
compoundKey: primaryKey(userItems.product_id, userItems.user_id),
}
)
)

export const userItemsRelations = relations(userItems, ({one}) => ({
product: one(products, {
fields: [userItems.product_id],
references: [products.id]
}),

user: one(users, {
fields: [userItems.user_id],
references: [users.id]
}),
}))
export const userItems = pgTable("userItem", {
product_id: serial("product_id").notNull(),
user_id: text("user_id").notNull(),
quantity: integer("quantity")
},
(userItems) => ({
compoundKey: primaryKey(userItems.product_id, userItems.user_id),
}
)
)

export const userItemsRelations = relations(userItems, ({one}) => ({
product: one(products, {
fields: [userItems.product_id],
references: [products.id]
}),

user: one(users, {
fields: [userItems.user_id],
references: [users.id]
}),
}))
You can see a small part of my schema. In fact, I can add a user item even when the product_id, that refers to my product id, doesn't exist. How can I tackle this issue ? I should check before the insert in my request? Thanks
7 replies