Skip to content

Commit 82b8b87

Browse files
lorefnoncmoog
authored andcommitted
Disable type-casting for date/time etc. in mysql and postgres
1 parent a6cc684 commit 82b8b87

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/driver.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ async function createMySQLPool({
155155
password,
156156
database,
157157
multipleStatements,
158+
typeCast(field, next) {
159+
switch (field.type) {
160+
case 'TIMESTAMP':
161+
case 'DATE':
162+
case 'DATETIME':
163+
return field.string();
164+
default:
165+
return next();
166+
}
167+
},
158168
}),
159169
queryTimeout
160170
);
@@ -210,6 +220,8 @@ interface PostgresConfig extends BaseConfig {
210220
driver: 'postgres';
211221
}
212222

223+
const identity = <T> (input: T) => input;
224+
213225
async function createPostgresPool({
214226
host,
215227
port,
@@ -225,6 +237,21 @@ async function createPostgresPool({
225237
database,
226238
user,
227239
query_timeout: queryTimeout,
240+
types: {
241+
getTypeParser(id, format) {
242+
switch (id) {
243+
case pg.types.builtins.TIMESTAMP:
244+
case pg.types.builtins.TIMESTAMPTZ:
245+
case pg.types.builtins.TIME:
246+
case pg.types.builtins.TIMETZ:
247+
case pg.types.builtins.DATE:
248+
case pg.types.builtins.INTERVAL:
249+
return identity;
250+
default:
251+
return pg.types.getTypeParser(id, format);
252+
}
253+
}
254+
}
228255
});
229256
return postgresPool(pool);
230257
}

0 commit comments

Comments
 (0)