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
But there is complete lack when it comes behaviour of library while serializing Javascript objects used as values inside pool.query or client.query method.
For example, if i pass a Moment object, how is it serialized? Is it done by calling Moment#toString() method? What if a library user wants to describe custom srialization behaviour? As I want to use Moment#toISOString() whenever a Moment object is passed to query.
Lets consider an example:
CREATETABLEIF NOT EXISTS RefreshToken (
id SERIALPRIMARY KEYNOT NULL,
token TEXTNOT NULL,
expires_at TIMESTAMPTZNOT NULL
);
importmomentfrom'moment';consttoken="xxxxx.yyyyy.zzzzz";constexpires_at=moment().add(1,'days');// local time zoneconstresult=awaitpool.query({text: 'INSERT INTO RefreshToken(token, expires_at) VALUES ($1, $2)',values: [token,expires_at.toISOString()// I want ISO-8601 UTC timestamp to be passed to Postgres. But it is so easy to forget to call toISOString on every query.],});
Is there any thing like require('pg').types.setTypeSerializer(Moment /* Javascript Type*/, serializeFn)???
The text was updated successfully, but these errors were encountered:
Parsing Postgres types is well documented on node-pg-types like to parse every
TIMESTAMPZ
type into aMoment
object, we can do something like:But there is complete lack when it comes behaviour of library while serializing Javascript objects used as
values
insidepool.query
orclient.query
method.For example, if i pass a
Moment
object, how is it serialized? Is it done by callingMoment#toString()
method? What if a library user wants to describe custom srialization behaviour? As I want to useMoment#toISOString()
whenever aMoment
object is passed to query.Lets consider an example:
Is there any thing like
require('pg').types.setTypeSerializer(Moment /* Javascript Type*/, serializeFn)
???The text was updated successfully, but these errors were encountered: