pglite icon indicating copy to clipboard operation
pglite copied to clipboard

feat: add custom parser and serializer to PGlite options

Open 0xOlias opened this issue 4 months ago • 0 comments

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.

0xOlias avatar Oct 18 '24 00:10 0xOlias