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
  • Loading branch information
gp27 committed Dec 17, 2024
1 parent 4e50547 commit d3e156a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,20 @@ function construct<TSchema extends Record<string, unknown> = Record<string, neve
$client: Sql;
} {
const transparentParser = (val: any) => val;
const dateSerializer = (val: any): any => {
if (val instanceof Date) { // eslint-disable-line no-instanceof/no-instanceof
return val.toISOString();
}
if (Array.isArray(val)) {
return val.map((d) => dateSerializer(d));
}
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 d3e156a

Please sign in to comment.