-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top-level type parser #315
Comments
this is very important for people trying to use PgLite for testing. We need to be able to match the way PgLite parses with the production driver |
const pg = await PGlite.create({
parsers: {
[types.TEXT]: (value) => value.toUpperCase(),
},
}); One reason not to choose this approach is that whoever is creating the // test-setup.ts
const client = await PGlite.create({
parsers: {
[types.TEXT]: (value) => value.toUpperCase(),
},
});
const db = drizzle({ client }); For this reason, I recommend pg.setParser(types.TEXT, (value) => value.toUpperCase()); or even mimic the node-postgres API directly given how popular that project is: pg.setTypeParser(types.TEXT, (value) => value.toUpperCase()); That way, libraries like Drizzle can use the API to work around incompatibilities without having to push the work to the application developer. |
Doesn't this already exist? https://pglite.dev/docs/api or am I misunderstanding? It doesn't seem to have an instance method though as suggested. If that is what is really wanted, then the issue title should be adjusted. |
Great callout, @jadejr! And although there's no instance method, there is a public setter. This fixes the issue with Drizzle: const pglite = await PGlite.create({...})
const db = drizzle({ client });
// Fixes https://github.com/drizzle-team/drizzle-orm/issues/3997
client.serializers[types.JSON] = (value) => value;
client.serializers[types.JSONB] = (value) => value; but this does not: const pglite = await PGlite.create({
serializers: {
[types.JSON]: (value) => value,
[types.JSONB]: (value) => value,
}
})
const db = drizzle({ client }) because Drizzle (incorrectly) overrides the parsers. That's a Drizzle bug, but it shows the importance of flexibility here. |
It would be great to be able to set a custom type parser for postgres data types at an instance level in addition to the query level. I'd be happy to work on this pr, but wanted to get some input on how it should look first.
API
It should probably be one or the other, which one do you think fits in best?
Relevant examples
node-postgres
drizzle-orm
The text was updated successfully, but these errors were encountered: