How to define types for jsonb
How do you provide custom type interfaces for jsonb columns returned via queries.
for instance if i have a column:
myfield: jsonb('data').notNull()
i want to be able to define a type interface for myfield
such that when i do const { myfield } = await db.query.myTable.findFirst({})
, the type of myfield is customized instead of unknown
im aware of this page in the docs (https://orm.drizzle.team/docs/custom-types) but i think this is not actually for what im talking about but maybe im dumbCommon way of defining custom types – DrizzleORM
Drizzle ORM | %s
5 Replies
myfield: jsonb<{ a: number }>('data').notNull()
i feel like this would be a clean way to do itthis is what i did but wondering if theres a better way
i guess it feels like this ought to not require me manually creating
typedJsonb
the docs say to use
$type<MyType>()