Error using the query param
So I'm getting a '''Property 'staff' does not exist on type 'DrizzleTypeError<...>'" when i try to run the query
''' const user = await db.query.staff.findMany({ where: eq(staff.email, email.toString()) }) '''' , my staff table exists in the schema and its is impoeted in the file
''' const user = await db.query.staff.findMany({ where: eq(staff.email, email.toString()) }) '''' , my staff table exists in the schema and its is impoeted in the file
8 Replies
Can you show how how you're instantiating the db object?
@Angelelz, I am seeing many posts of this for some reason.
This is essentially my code. Importing the schema to drizzle, exporting a user and its relationship.
For some reason vscode is complaining about this
Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339) anyThis is not a big problem since the code work itself, it's just typescript that complains, but it would be nice to see that everything is properly setup 🤓
I see
I don't use cloudflare. I think your problem is that you don't have your locals type declared properly
You mean what I export from
$lib/db/schema
?event.locals.D1
Is that type defined somewhere?
This is in one of the sequences in hooks.server.ts in sveltekit
event.locals.D1 is defined in my
app.d.ts
file under Platform and Locals interface
Defined as D1: DrizzleD1Database;
But I am missing the schema... so I guess I need to add it there
drizzle return type is : DrizzleD1Database<typeof schema>
I'm not type expert hereHow does it get from locals to the db object you're using for your query?
Are the relations being imported from the schema too?
The relations are exported from the schema so I would assume they're also imported.
When I make a db call, I simply reference teh D1 instance on
event.locals.D1
that is previously setup.