Skip to content

Commit

Permalink
Properly handle dates in RDS Data API
Browse files Browse the repository at this point in the history
  • Loading branch information
dankochetov committed Dec 7, 2023
1 parent d55aea4 commit 47754fb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drizzle-orm/src/aws-data-api/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,28 @@ export function toValueParam(value: any, typings?: QueryTypingsValue): { value:
if (value === null) {
response.value = { isNull: true };
} else if (typeof value === 'string') {
response.value = response.typeHint === 'DATE'
? { stringValue: value.split('T')[0]! }
: { stringValue: value };
switch (response.typeHint) {
case TypeHint.DATE: {
response.value = { stringValue: value.split('T')[0]! };
break;
}
case TypeHint.TIMESTAMP: {
response.value = { stringValue: value.replace('T', ' ').replace('Z', '') };
break;
}
default: {
response.value = { stringValue: value };
break;
}
}
} else if (typeof value === 'number' && Number.isInteger(value)) {
response.value = { longValue: value };
} else if (typeof value === 'number' && !Number.isInteger(value)) {
response.value = { doubleValue: value };
} else if (typeof value === 'boolean') {
response.value = { booleanValue: value };
} else if (value instanceof Date) { // eslint-disable-line no-instanceof/no-instanceof
// TODO: check if this clause is needed? Seems like date value always comes as string
response.value = { stringValue: value.toISOString().replace('T', ' ').replace('Z', '') };
} else {
throw new Error(`Unknown type for ${value}`);
Expand Down

0 comments on commit 47754fb

Please sign in to comment.