Comments (6)
Quick update - I've narrowed down the source of the issue to instances where a date is passed to the sql
operator, either directly (sql`${dateHereWillBreakThings}
) or in a sql.placeholder(date)
. Doing that worked in v 0.29.x, but not in 0.30.x.
It still works to pass a date to a filter operator (e.g. gte(sessions.timestamp, startDate)
).
The workaround that worked for me for now is to convert any dates used with the sql
operator to strings, like sql`${date.toISOString()}
.
from drizzle-orm.
I am having the same issue on version 0.30.4
when i pass Date objects to queries. The last version on which passing a Date worked correctly was 0.29.3
from drizzle-orm.
@gp27 Please keep me posted if you find a solution or workaround for this. I'm surprised that more people don't appear to be experiencing this since it's such a basic use case, so I feel like I must be overlooking something obvious.
from drizzle-orm.
I tried to investigate this issue further.
I think it has been introduced with this PR #1659, which fixed an issue with the postgres driver where timestamps with mode "string" that should have been returned by queries as string values, were actually parsed into Date objects.
When the parsers for timezone related types were switched, so were the serializers:
https://github.com/Angelelz/drizzle-orm/blob/b29a5e1a837cbbb45be5e2caf3564c0493c28d08/drizzle-orm/src/postgres-js/driver.ts#L28
The replacements of those serializers is probably what is causing this issue and #2009 as well.
I am not sure it was necessary to replace the serialziers as well, since the issue was on the parsing side, but I may be wrong. Maybe @Angelelz who authored the fix might have some further info about it.
from drizzle-orm.
The replacement of the serializer and parsers was necessary to guarantee that the same parsing/serializer code from Drizzle will work for both postgres.js and node-PG interchangeably. Unfortunately I have very little time lately to dedicate to drizzle but if somebody puts together a quick reproduction it will make it easier to investigate/fix.
from drizzle-orm.
Until this is solved, a temporary workaround is to create a custom type:
import { customType } from "drizzle-orm/pg-core"
export const customDate = customType<{
data: string
driverData: Date
}>({
dataType() {
return "date"
},
fromDriver(value: Date): string {
return value.toISOString().slice(0, 10)
},
})
from drizzle-orm.
Related Issues (20)
- [BUG]: Invalid schema generation on postgres instrospect HOT 1
- [BUG]: drizzle-kit introspect TypeError: Cannot read properties of undefined (reading 'toLowerCase') HOT 2
- [BUG]: multiple constraints not added (only the first one is generated) HOT 3
- [BUG]: Relation Query type merges when using the same "with" key
- [BUG]: TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys') HOT 1
- [BUG]: drizzle-kit generate not detecting schema changes HOT 2
- [BUG]: Column conflicts are not getting resolved by drizzle-kit HOT 2
- [BUG]: Error: There is not enough information to infer relation for many-to-many relationship HOT 1
- [FEATURE]: findOrCreate
- [FEATURE]: Return insert id as the result of insert statement HOT 2
- [FEATURE]: Migration Rollback feature
- [BUG]: drizzle-zod generates ZodString type for numeric field
- [BUG]: drizzle-kit migrate doesn't exit 1 on error HOT 1
- [BUG]: IF NOT EXISTS in Migrations leads to inconsistencies
- [FEATURE]: Add support for new `pipe` syntax for drizzle-valibot
- [FEATURE]: onConflictDoUpdate() empty argument overload
- [BUG]: Date with a `.toISOString()` causes an error in the `typeHint` with PostgreSQL HOT 1
- One relation isNullable property should be !notNull rather than notNull
- [BUG]: Migrations no longer execute in 0.21.3
- [BUG]: Drizzle-kit push not making changes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drizzle-orm.