pglite
pglite copied to clipboard
feat: add custom parser and serializer to PGlite options
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.