fdarian / prisma-generator-drizzle

A Prisma generator for generating Drizzle schema with ease
129 stars 11 forks source link

Typed JSON? #77

Open sgup opened 1 month ago

sgup commented 1 month ago

Hi, is there a way to support typed JSON's ?

https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-json-fields#typed-json

I added custom types in my drizzle schema (https://orm.drizzle.team/docs/column-types/pg#jsonb), but unfortunately they get overwritten with every change/generate.

fdarian commented 1 month ago

You can use drizzle.custom directive for now. Please let me know how the syntax feels.

sgup commented 1 month ago

Hmm, not working for me:

schema.prisma

  /// drizzle.custom {
  ///   "$type": "{ month: string, min: number, max: number }[]",
  /// }
  tempRanges Json?

I'm trying to generate this in drizzle.schema:

  tempRanges: jsonb("tempRanges").$type<{ month: string, min: number, max: number }[]>(),

I tried wrapping with <> as well in the comment.

image