Next.js Discord

Discord Forum

Drizzle Schema Boolean Conditional

Unanswered
Ant posted this in #help-forum
Open in Discord
AntOP
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'),


I want to have these contentType and contentUrl columns to contain value only when isProtected is true. Is there a way to make sure that these columns will only contain values when isProtected is true ?

1 Reply

AntOP
If someone could point me in the right direction, I'd really appreciate it