Reputation: 5
I'm setting up a test project with SvelteKit, using MySQL for the DB and Drizzle as an ORM. It's using TypeScript.
This is the db/index.ts file:
import { drizzle } from 'drizzle-orm/mysql2';
import { DB_URL } from '$env/dynamic/private';
export const db = drizzle(DB_URL);
Then I import the db file into +page.server.ts:
import { db } from '$lib/db';
and I get the below error
TypeError: Cannot read properties of undefined (reading 'promise')
at isCallbackClient (file:///home/user/x/node_modules/drizzle-orm/mysql2/driver.js:62:24)
at construct (file:///home/user/x/node_modules/drizzle-orm/mysql2/driver.js:36:29)
at drizzle (file:///home/user/x/node_modules/drizzle-orm/mysql2/driver.js:82:10)
at /home/user/x/src/lib/db/index.ts:4:19
I'm not sure what I'm missing. This is entirety of the two files. I commented out and removed everything else from the +page.server.ts file, there was nothing else in the db module (db/index.ts)
What am I missing?
Upvotes: 0
Views: 228
Reputation: 26
I've not used Drizzle myself, so I can only really speculate (Throw ideas out and see if any sticks).
The callback is saying this error is coming from your node_modules folder, specifically your drizzle driver. I've looked at the drizzle Github and first noticed that your callback is missing the /src/ folder in the filepath, implying that your version of drizzle is incongruent with the current version hosted on github.
1.) You could uninstall and reinstall drizzle and verify you are using 0.38.2 (latest at time of writing).
2.) The error itself appears to be because your Client is undefined. Manually set the client to either ClientConnection or PoolConnection: https://orm.drizzle.team/docs/get-started-mysql
3.) Verify your DB URL is correct. You can do this by throwing a
const response = await db.select().from(...)
into your index.ts file and seeing if it goes through. Or verify the URL manually.
postgresql://alex:[email protected]/dbname
└──┘ └───────┘ └─────────────────────────────────────────────┘ └────┘
ʌ ʌ ʌ ʌ
role -│ │ │- hostname │- database
│
│- password
4.) If none of this works, you could try a shot in the dark and declare the DB inside the page.server.ts file itself. It could be that the declaration is what establishes the connection, and this connection fails when exported to another file. I don't know why this would be the case, but every example I've looked at declares the DB in the same file that queries it.
Upvotes: 1