Type error working with Postgres dates in v.0.30.1

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. After the update, 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))
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<string>, right: string | SQLWrapper): SQL<unknown>', 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<string>'.
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<string>, right: string | SQLWrapper): SQL<unknown>', 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<string>'.
Any tips would be appreciated. Thank you!
7 Replies
terryball
terryballOP8mo ago
Giving this a quick bump to see if anyone else has experienced this or has any tips to solve. It's currently blocking me from upgrading to v 0.30.x, so I'm very curious. Thanks!
nateeo
nateeo8mo ago
@terryball I had a similar problem to you upgrading to 0.30.x and couldn't get queries with dates inside gte working — for me I ended up replacing the gte/lte calls with between which doesn't seem to have the same issue. For example: between(posts.created_at, startDate, endDate), but that doesn't seem ideal if you don't want to pass in an endDate (could just set it to now though). I plan to look deeper to see what the actual issue is later
terryball
terryballOP8mo ago
Interesting, ok thanks @nateeo
francis
francis8mo ago
it may depend on the mode you are using for the column, no?
NeonCop
NeonCop4mo ago
seeing this too, even when I have the column in date mode, I get a typescript error if i have it as a iso string, and a runtime error if i leave it as a date. The between fix doesn't even work for me 😦 @Angelelz
Matoslav
Matoslav3mo ago
any update for this?
francis
francis3mo ago
this has been resolved for ages now I think
Want results from more Discord servers?
Add your server