drizzle-team / drizzle-team/drizzle-orm
[BUG]: Type error with postgresjs strings/dates in version 0.30
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.30.1
### What version of `drizzle-kit` are you using?
0.20.14
### Describe the Bug
I'm using Drizzle with postgresjs and recently updated to v0.30.1, where I know the driver was updated to always return strings for dates.
Many of my queries then failed with an error `ERR_INVALID_ARG_TYPE`: `The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date"`.
Here's an example of a failed query that produced that error message:
```
const startDate = subDays(new Date(), 30) // Date object
const results = await db
.select({
id: sessions.id,
userId: sessions.userId,
})
.from(sessions)
.where(gte(sessions.timestamp, startDate))
```
Where `sessions.timestamp` is defined as `timestamp('timestamp', { mode: 'date', withTimezone: true })` in my schema.
When I convert `startDate` to a string with `.toISOString()`, the query works, but I get the following type error:
```
No overload matches this call.
Overload 1 of 3, '(left: PgColumn<{ name: "timestamp"; tableName: "sessions"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>, right: Date | SQLWrapper): SQL<...>', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'Date | SQLWrapper'.
Overload 2 of 3, '(left: Aliased, right: string | SQLWrapper): SQL', gave the following error.
Argument of type 'PgColumn<{ name: "timestamp"; tableName: "sessions"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased'.
Type 'PgColumn<{ name: "timestamp"; tableName: "sessions"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased': sql, fieldAlias
Overload 3 of 3, '(left: never, right: unknown): SQL', gave the following error.
Argument of type 'PgColumn<{ name: "timestamp"; tableName: "sessions"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'never'.ts(2769)
```
Any tips would be appreciated. Thank you!
### Expected behavior
_No response_
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.