You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be no way to override the type parser other than createClient (which then requires manually closing connections).
createPool accepts the types option, but ignores it
pg-types types.setTypeParser is ignored
db.connect does not accept the types option
sql'Foo' does not accept the types option
I assume this is a bug for createPool, but also seems like the pg-types approach should work for compatibility sake.
Environment
Running locally, using Next.js, connected to a cloud vercel-psql instance
version: 0.7.2
Snippets
Supplying the type parser to createPool has no impact.
constpool=createPool({types: {getTypeParser: (typeId,format)=>{console.log("This function is never invoked");},},});
Calling setTypeParser has no impact
importtypesfrom"pg-types";types.setTypeParser(types.builtins.INT8,()=>{console.log("This function is never invoked");});
Create client on the on the other hand, does work.
But this option is unappealing in many cases because that then requires manually closing the client connection.
constclient=createClient({types: {getTypeParser: (typeId,format)=>{console.log("This function is called as expected")},},});
Further context
My actual use case is to override the bigint parser with one that converts it to a JS-float rather than a string.
The following snippet technically works. But my specific setup does not have a great spot to close the DB connection, making it rather unappealing.
importtypesfrom"pg-types";constintegerParser=(value: string): number=>{constint=parseInt(value);if(isNaN(int))thrownewError(`Unable to parse integer "${value}"`);if(int>=Number.MAX_SAFE_INTEGER)thrownewError(`Integer "${value}" exceeds maximum safe size`);returnint;};constclient=createClient({types: {getTypeParser: (typeId,format)=>{switch(typeId){casetypes.builtins.INT8:
returnintegerParser;default:
returntypes.getTypeParser(typeId,format)asunknown;}},},});
The text was updated successfully, but these errors were encountered:
There seems to be no way to override the type parser other than
createClient
(which then requires manually closing connections).createPool
accepts thetypes
option, but ignores ittypes.setTypeParser
is ignoreddb.connect
does not accept thetypes
optionsql'Foo'
does not accept thetypes
optionI assume this is a bug for
createPool
, but also seems like thepg-types
approach should work for compatibility sake.Environment
0.7.2
Snippets
Supplying the type parser to
createPool
has no impact.Calling
setTypeParser
has no impactCreate client on the on the other hand, does work.
But this option is unappealing in many cases because that then requires manually closing the client connection.
Further context
My actual use case is to override the
bigint
parser with one that converts it to a JS-float rather than a string.The following snippet technically works. But my specific setup does not have a great spot to close the DB connection, making it rather unappealing.
The text was updated successfully, but these errors were encountered: