Closed berenddeboer closed 8 months ago
OK, just leaving this here for someone else stumbling on this: if you mock postgres, you now need to make sure you return an options object, with an empty parsers and serializers array.
This still happens to me.
/node_modules/src/postgres-js/driver.ts:27 client.options.parsers[type as any] = transparentParser; ^ TypeError: Cannot read properties of undefined (reading 'parsers') at drizzle( r/node_modules/src/postgres-js/driver.ts:27:18) at testRunMigrations ( /migrations/run_migrations.ts:22:14) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Node.js v20.11.0 drizzle-kit: v0.20.14 drizzle-orm: v0.30.6
This is my code
const client = new Client({
connectionString: DatabaseConfig.postgresqlConnection,
});
await client.connect(); // It connects
const db = drizzle(client, { schema: { ...jobs } });
https://github.com/drizzle-team/drizzle-orm/issues/2028#issuecomment-2002635197
@berenddeboer what did you change?
@iursevla Hopefully this will help you or others like me that get here for the same reason. If you change database drivers e.g. to switch from postgres-js
to node-postgres
make sure you:
import {drizzle} from 'drizzle-orm/postgres-js';
import {PostgresJsDatabase} from 'drizzle-orm/postgres-js/driver';
becomes:
import {drizzle} from 'drizzle-orm/node-postgres';
import {NodePgDatabase} from 'drizzle-orm/node-postgres/driver';
Thanks @crrobinson14 for taking the time to reply. I've since figured it out and also created a little repo to showcase multiple schemas: https://github.com/intruder-detection/nestjs-drizzle-multiple-schemas
@iursevla Very nice contribution! Love the reusable DAO too. It's my one dislike of Drizzle - the API surfaces between .query and .select|insert|update|delete aren't quite the same, and many common operations like findByPK take a fair bit of code. I miss ActiveRecord approaches to this. I love what you did in type safety there.
What version of
drizzle-orm
are you using?0.30.2
What version of
drizzle-kit
are you using?0.24.14
Describe the Bug
Switching to 0.30.2 gives a very odd error when instantiating drizzle. Code working fine with previous version. Code looks like this:
Error happens on creating drizzle. I tried to add
options
to both postgres and drizzle but didn't seem to help.Expected behavior
Code working without changes.
Environment & setup
This happens with a mocked postgres driver. This is probably the issue.