Cannot read properties of undefined (reading 'findMany')
Hello, I have a simple schema and an empty table and I can call my database wiith sqllike query but not with the querybuilder, i dont understand why, am I missing something?
ty guys
18 Replies
What you shared here is written
const accounts
it needs to be export const accounts
if it is not that is likely the error. If not, let me know.
Oh and I'm talking about your schema. You need to export everything in your schema
Then you can import itOh yeah mb didnt put the exports in my example
Its not the error tho
Is
the whole error?
should be
it is sorry, its my bad i corrected it with my phone
the problem is :
that line is working
const manies = await con.select().from(accounts)
but that line not working const manies2 = await con.query.accounts.findMany()
i dont understand how its possible i have to be missing soemthingOh I think you need to define schema in your drizzle connection.
Here's code snipped from my project:
I believe this is required if you want to use
db.query
can can you show me how you call it?
like a findMany
same like you did
He is talking about passing your schema to drizzle()
yes ive just done it
Your findMany is written correctly. Does the query work now?
same error
nah, same error
ok new error
its now findMany() who is undefined again, so he knows my schema
You shouldn't need to create a pool. just pass you sql connection directly as the first parameter then pass schema as an object
Also just curious why are you not just using
import/export
I can't think of reason for your node version to not be 16+ should have support for es modules
in that case schema is my unique accounts schema or the object that countain all my schema like {accounts, schema2 ... } ?
because i cant use "type":"module" in my package.json dunno why
check your node version preferably you should be in 16 at least
its 18
it can also be
but it's simpler to import everything from your schema file and name it
schema
, so you can pass that to your drizzle(). just like I did in code snippet I sent from my project
and then whenever you define new tables to that file it will already be passed to drizzle(), since it's taking everything from that file