You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with the column mode set to string on timestamp typescript infers string, but runtime returns Date at runtime dueAt: timestamp("dueAt", {mode: "string"}).notNull(),
Intialising drizzle with drizzle from drizzle-orm/vercel-postgres
I saw there was a mention in 0.30.0 that there was a fix to ensure that it returns string type, however it does not seem to apply to vercel-postgres or neon-serverless?
If i check drizzle-orm/pg-core/colums/timestamp.tsthere is no override for mapFromDriverValue on PgTimestampString should there be some kind of transformation happening here, or have i misunderstood the mode: "string"config?
If i modify drizzle-orm/pg-core/colums/timestamp.js in node_modules with mapFromDriverValue implementation as a test it will, naturally, return string in format as expected.
classPgTimestampStringextendsPgColumn{static[entityKind]="PgTimestampString";withTimezone;precision;constructor(table,config){super(table,config);this.withTimezone=config.withTimezone;this.precision=config.precision;}mapFromDriverValue=(value)=>{//not handling precisionif(typeofvalue!=="string"){constf=(i)=>(i<10 ? `0${i}` : `${i}`);consty=`${value.getFullYear()}`;constm=f(value.getMonth()+1);constd=f(value.getDate());consth=f(value.getHours());constmi=f(value.getMinutes());consts=f(value.getSeconds());return`${y}-${m}-${d}${h}:${mi}:${s}`;}returnvalue;};getSQLType(){constprecision=this.precision===void0 ? "" : `(${this.precision})`;return`timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;}}
After some more investigation:
If i switch to use a neon database and connect initialise drizzle through drizzle-orm/neon-serverlessthe return type is string as expected
if i connect to the same database using drizzle-orm/vercel-postgres the return type is Date
if i connect to my vercel database using the neon driver, it returns string as expected
Could it be related to these lines that setTypeParser are commented out in the vercel-postgres driver?
If i try to enable setting of the type parsers in vercel-postgres/driver.js they have no affect.
However if i edit the VercelPool constructor in create-pool.ts of @vercel/postgres and add the setting of type parser directly there it works and string type is returned as expected:
kimdanielarthur-cowlabs
changed the title
[BUG]: Return type of timestamp with mode "string" using vercel-postgres or neon-serverless is Date and not string
[BUG]: Return type of timestamp with mode "string" using vercel-postgres is Date and not string
Mar 23, 2024
We have switched to use neon databases directly rather than vercel, for other reasons, and with that using the neon driver to connect. So won1t be able to test as easily. I'll see if I can get a test project set up
What version of
drizzle-orm
are you using?0.30.4
What version of
drizzle-kit
are you using?0.20.14
Describe the Bug
with the column mode set to string on timestamp typescript infers string, but runtime returns Date at runtime
dueAt: timestamp("dueAt", {mode: "string"}).notNull(),
Intialising drizzle with
drizzle
fromdrizzle-orm/vercel-postgres
I saw there was a mention in 0.30.0 that there was a fix to ensure that it returns string type, however it does not seem to apply to vercel-postgres or neon-serverless?
If i check
drizzle-orm/pg-core/colums/timestamp.ts
there is no override formapFromDriverValue
onPgTimestampString
should there be some kind of transformation happening here, or have i misunderstood themode: "string"
config?If i modify
drizzle-orm/pg-core/colums/timestamp.js
innode_modules
withmapFromDriverValue
implementation as a test it will, naturally, return string in format as expected.After some more investigation:
drizzle-orm/neon-serverless
the return type is string as expecteddrizzle-orm/vercel-postgres
the return type is DateCould it be related to these lines that setTypeParser are commented out in the vercel-postgres driver?
If i try to enable setting of the type parsers in
vercel-postgres/driver.js
they have no affect.However if i edit the VercelPool constructor in create-pool.ts of @vercel/postgres and add the setting of type parser directly there it works and string type is returned as expected:
I'll see if i can find a way to set those type parsers externally through the exported objects somehow.
A "workaround" is to just use
drizzle-orm/neon-serverless
to connect to the vercel database which it seems to do underlying anyway.Expected behavior
expect timestamp with mode:"string" to return string type at runtime
Environment & setup
"@vercel/postgres": "0.7.2",
"@neondatabase/serverless": "^0.9.0",
Vercel postgres database
select version()
: "PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"The text was updated successfully, but these errors were encountered: