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

feat: add custom parser and serializer to PGlite options #397

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

0xOlias
Copy link

@0xOlias 0xOlias commented Oct 18, 2024

This PR adds support for custom serializers to QueryOptions, and adds support for custom parsers and serializers to PGliteOptions. The change is non-breaking.

Our use case is using NUMERIC columns to store integers too large for BIGINT. We'd like these values to use the JS native BigInt rather than String, and it's easiest if this happens at the driver layer.

import { NUMERIC, PGlite, type PGliteOptions } from "@electric-sql/pglite";

export function createPglite(options: PGliteOptions) {
  return new PGlite({
    serializers: { [NUMERIC]: (x: string | number | bigint) => x.toString() },
    parsers: { [NUMERIC]: (x: string) => BigInt(x) },
    ...options,
  });
}

Verified locally in an integration test with our framework.

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

Successfully merging this pull request may close these issues.

1 participant