Skip to content
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

Open
kyscott18 opened this issue Sep 12, 2024 · 0 comments
Open

Top-level type parser #315

kyscott18 opened this issue Sep 12, 2024 · 0 comments

Comments

@kyscott18
Copy link

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

import { PGlite, types } from '@electric-sql/pglite';

const pg = await PGlite.create({
 parsers: {
    [types.TEXT]: (value) => value.toUpperCase(),
  },
});

// or 

const pg = await PGlite.create();
pg.setParser(types.TEXT, (value) => value.toUpperCase());

It should probably be one or the other, which one do you think fits in best?

Relevant examples

node-postgres

var types = require('pg').types;
types.setTypeParser(20, function(val) {
  return parseInt(val, 10)
});

drizzle-orm

const users = pgTable('users', {
  // set custom column type with ".$type"
  id: serial('id').$type<UserId>().primaryKey(),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant