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 dumb
5 Replies
jakeleventhal
jakeleventhalOP17mo ago
myfield: jsonb<{ a: number }>('data').notNull() i feel like this would be a clean way to do it
jakeleventhal
jakeleventhalOP17mo ago
this is what i did but wondering if theres a better way
jakeleventhal
jakeleventhalOP17mo ago
i guess it feels like this ought to not require me manually creating typedJsonb
micaww
micaww17mo ago
the docs say to use $type<MyType>()
Want results from more Discord servers?
Add your server