Closed JasoonS closed 1 month ago
Still happens in version 2.6.13. It would be a godsend to have this working in projecst using drizzle-orm.
I've dived deeper into the root cause of this error. It seems that the error is happening because Drizzle is calling queries in some mixed way.
client.query({ text: `INSERT INTO "drizzle"."__drizzle_migrations" ("hash", "created_at") VALUES ($1, $2);` }, [
'e42357b891c213208519fe4696442450b98c6fcbd32562a6eab5bfd1225b5b3f',
1690826882833
])
Based on node-postgress
docs they recommend using either:
client.query(`INSERT INTO "drizzle"."__drizzle_migrations" ("hash", "created_at") VALUES ($1, $2);`, [
'e42357b891c213208519fe4696442450b98c6fcbd32562a6eab5bfd1225b5b3f',
1690826882833
])
or
client.query({
text: `INSERT INTO "drizzle"."__drizzle_migrations" ("hash", "created_at") VALUES ($1, $2);`,
values: [
'e42357b891c213208519fe4696442450b98c6fcbd32562a6eab5bfd1225b5b3f',
1690826882833
]})
Inside pg-mem
method called adaptQuery
doesn't support such a mixed approach.
I was able to work around this issue by propagating values
to query
when query.values
doesn't exist.
private adaptQuery(query: string | PgQuery, values: any): PgQuery {
if (typeof query === 'string') {
query = {
text: query,
values,
};
} else {
// clean copy to avoid mutating things outside our scope
query = { ...query, values: query.values || values }; // <- before it was `{ ...query }`
}
if (!query.values?.length) {
return query;
}
if (query.types?.getTypeParser) {
throw new NotSupported('getTypeParser is not supported');
}
// console.log(query);
// console.log('\n');
query.text = replaceQueryArgs$(query.text, query.values);
return query;
}
I'm not sure where this should be fixed. Is that something that pg-mem
could support or drizzle internally should avoid using this "mixed" approach?
I'm also running into this issue when trying to test drizzle. @MateWW are you considering submitting a PR to pg-mem
with your fix?
@MateWW the proposed fix works great with my unit tests 👍
i think we should fix it here in pg-mem, since it seems to be a supported use-case of node-postgres
Describe the bug
When running drizzle migrations I get the following error:
To Reproduce
pg-mem version
2.6.12