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 Aug 24, 2024
1 parent 059b070 commit a0cabb7
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 @@ -21,11 +21,20 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
config: DrizzleConfig<TSchema> = {},
): PostgresJsDatabase<TSchema> {
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 a0cabb7

Please sign in to comment.