Types don't infer correctly for tables with`references` method?
I'm using Drizzle with Expo SQLite in an Expo managed app. On my schema all of the tables that contain simple column data, i.e. primitive types like
Even if I try to specify the type of the column with the
text
or int
, get typed correctly. Any time I create an association with the references
method the generated type becomes { [x: string]: any }
.
I'm using:
- Expo SDK: 51
- Expo SQLite: 14.0.6
- drizzle-orm: 0.44.2
- drizzle-kit: 0.31.1
I'll give an example directly from my schema.
In my schema I have the table movementTypes
and a join table that connects it with another table called characters
.Even if I try to specify the type of the column with the
$type<>()
method, I'm still not getting the correct type returned for the table's model.
Is there a way to get this to generate correctly? I'd be happy with a solution that requires passing types as args or generated by the drizzle api.
Thanks in advance for any help!2 Replies
Since no answer's been given yet, I thought I'd update with what I found when adding a new join table so others may find the solution.
It's buried in the docs in the Foreign Key constraint docs.
In the 2nd example for self references the anonymous function passed as a callback to the
references
call is typed with the AnySQLiteColumn
type. This seems to make the types generate correctly, as far as I can tell.
An updated example of my new model is as follows:
Drizzle ORM - Indexes & Constraints
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
It did require removing the explicit foreign key constraints, however.
To demonstrate this, here is an example of both with and without the explicit foreign key constraints and the resulting types generated for both examples.
This stuff is never explicitly called out in the docs, which I think would be a huge improvement for them. It's also not mentioned in the section pertaining to relations as all of those examples are given with PGSql examples only.