Skip to content

Commit

Permalink
bugfix: Fixed postgres-js date serializer to handle Date objects
Browse files Browse the repository at this point in the history
Signed-off-by: Gadi Piperno Corcos <gadi@skyriseltd.com>
  • Loading branch information
gp27 committed Jan 7, 2025
1 parent 81628ed commit 586e8f8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drizzle-orm/src/postgres-js/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
$client: Sql;
} {
const transparentParser = (val: any) => val;
const dateSerializer = (val: unknown): unknown => {
if (Object.prototype.toString.call(val) === '[object Date]') {
return (val as Date).toISOString()
}
return val
}

// Override postgres.js default date parsers: https://github.com/porsager/postgres/discussions/761
for (const type of ['1184', '1082', '1083', '1114']) {
client.options.parsers[type as any] = transparentParser;
client.options.serializers[type as any] = transparentParser;
client.options.serializers[type as any] = dateSerializer;
}
client.options.serializers['114'] = transparentParser;
client.options.serializers['3802'] = transparentParser;
Expand Down

0 comments on commit 586e8f8

Please sign in to comment.