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.
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:Jump to 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...
6 Replies
I've heard about generated columns but not sure if its what I need
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...
Thank you, I guess its not implemented in Drizzle ORM yet https://orm.drizzle.team/docs/indexes-constraints#check
Indexes & Constraints - DrizzleORM
Drizzle ORM | %s
Just use the SQL operator that drizzle provides
I'll try to do that, thank you.
@Josh I couldnt find any example for defining a column using the Drizzle's SQL operator and not giving away type-safety