Cody Oakes
Cody Oakes
DTDrizzle Team
Created by Cody Oakes on 1/7/2025 in #help
Generated Postgres Column adding together other columns that may have null values
This code works until one of the numeric values is null, then the totalQuantity becomes null as well. Is there a way to do this in a drizzle schema that would account for the potential nulls?
const supplyItem = pgTable('supply_item', {
id: bigint('id', { mode: 'number' }).primaryKey().generatedAlwaysAsIdentity(),
name: text('name').notNull(),
location1name: text('location1_name'),
location1quantity: numeric('location1_quantity'),
location2name: text('location2_name'),
location2quantity: numeric('location2_quantity'),
location3name: text('location3_name'),
location3quantity: numeric('location3_quantity'),
totalQuantity: numeric('total_quantity').generatedAlwaysAs(
(): SQL =>
sql`${supplyItem.location1quantity}+${supplyItem.location2quantity}+${supplyItem.location3quantity}`,
),
})
const supplyItem = pgTable('supply_item', {
id: bigint('id', { mode: 'number' }).primaryKey().generatedAlwaysAsIdentity(),
name: text('name').notNull(),
location1name: text('location1_name'),
location1quantity: numeric('location1_quantity'),
location2name: text('location2_name'),
location2quantity: numeric('location2_quantity'),
location3name: text('location3_name'),
location3quantity: numeric('location3_quantity'),
totalQuantity: numeric('total_quantity').generatedAlwaysAs(
(): SQL =>
sql`${supplyItem.location1quantity}+${supplyItem.location2quantity}+${supplyItem.location3quantity}`,
),
})
14 replies
DTDrizzle Team
Created by Cody Oakes on 9/11/2024 in #help
NextJS PGlite Drizzle setup?
Any thoughts/examples on what a NextJS (app router), PGlite, Drizzle setup looks like? Seems a bit tricky getting it all to run on client in NextJS with app router...
1 replies
DTDrizzle Team
Created by Cody Oakes on 11/23/2023 in #help
CockroachDB Support?
Just wondering if anyone knows if Drizzle would work with CockroachDB? Looks like they both support the node-postgres driver so I thought I'd have pretty good luck but my migration failed, and as I was looking around I noticed on the GitHub readme that support for CockroachDB is ⏳ which made me think maybe I should wait. Any timeline for official support? Thanks for the help!
1 replies