Drizzle Schema Boolean

Hi everyone, I'm trying to create a schema in Drizzle but my SQL knowledge is pretty limited. I want to have a boolean like isProtected and if this is true then store some other information in other columns. I dont know how to handle a situation like this.
isProtected: boolean('is_protected').default(false).notNull(),
contentType: mysqlEnum('content_type', [
'application/vnd.apple.mpegurl',
'text/xml',
]),
contentUrl: text('content_url'),
isProtected: boolean('is_protected').default(false).notNull(),
contentType: mysqlEnum('content_type', [
'application/vnd.apple.mpegurl',
'text/xml',
]),
contentUrl: text('content_url'),
I want to have these contentType and contentUrl columns to contain value only when isProtected is true. Basically, Is there a way to make sure that when I set to isProtected true Typescript will force me to add other related columns ?
Solution:
Generated columns are just made from combining data already in the table, https://stackoverflow.com/questions/10273750/sql-conditional-not-null-constraint should answer your question as far as i can tell
Stack Overflow
Sql Conditional Not Null Constraint
I am curious to know is it possible to create a conditional not null constraint in sql? In otherwords is it possible to create a constraint such that a column B can be null as long column A contain...
Jump to solution
6 Replies
Efkan
EfkanOP14mo ago
I've heard about generated columns but not sure if its what I need
Solution
Arctic
Arctic14mo ago
Generated columns are just made from combining data already in the table, https://stackoverflow.com/questions/10273750/sql-conditional-not-null-constraint should answer your question as far as i can tell
Stack Overflow
Sql Conditional Not Null Constraint
I am curious to know is it possible to create a conditional not null constraint in sql? In otherwords is it possible to create a constraint such that a column B can be null as long column A contain...
Efkan
EfkanOP14mo ago
Thank you, I guess its not implemented in Drizzle ORM yet https://orm.drizzle.team/docs/indexes-constraints#check
Josh
Josh14mo ago
Just use the SQL operator that drizzle provides
Efkan
EfkanOP14mo ago
I'll try to do that, thank you.
Efkan
EfkanOP14mo ago
@Josh I couldnt find any example for defining a column using the Drizzle's SQL operator and not giving away type-safety
Want results from more Discord servers?
Add your server