Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Dates are always dates #971

Closed
michaelgmcd opened this issue Aug 3, 2023 · 4 comments · Fixed by #1659
Closed

[BUG]: Dates are always dates #971

michaelgmcd opened this issue Aug 3, 2023 · 4 comments · Fixed by #1659
Assignees
Labels
bug Something isn't working

Comments

@michaelgmcd
Copy link
Contributor

What version of drizzle-orm are you using?

0.27.2

What version of drizzle-kit are you using?

0.19.12

Describe the Bug

When using the date() column type in postgres, (import { date } from 'drizzle-orm/pg-core';), the returned "date" property is always a Date object, regardless of the mode. On top of that, the TypeScript types describe the intended behavior, resulting in all sorts of bugs.

Expected behavior

The date column should respect the mode that is passed.

Environment & setup

Postgres, using the "date" column

@michaelgmcd michaelgmcd added the bug Something isn't working label Aug 3, 2023
@rtkevin
Copy link

rtkevin commented Aug 17, 2023

If using pg / node-postgres, this a feature you need to disable.

https://node-postgres.com/features/types#date--timestamp--timestamptz
"Likewise, when reading a date, timestamp, or timestamptz column value back into JavaScript, node-postgres will parse the value into an instance of a JavaScript Date object."

I've done it like this when working with knex.

import Pg from 'pg';
// {{{ stop node-postgres from parsing to date objects
function parseDt(val: unknown): unknown {
    return val;
}
Pg.types.setTypeParser(Pg.types.builtins.TIMESTAMPTZ, parseDt);
Pg.types.setTypeParser(Pg.types.builtins.TIMESTAMP, parseDt);
Pg.types.setTypeParser(Pg.types.builtins.DATE, parseDt);
// }}}

Issue noted on knex: knex/knex#3071 (comment)

@Angelelz Angelelz self-assigned this Dec 14, 2023
@AndriiSherman
Copy link
Member

Should be fixed in drizzle-orm@beta. I would appreciate some feedback to confirm whether this issue has been resolved in this tag.

I plan to release it in version 0.30.0 tomorrow or within the next few days; I simply aim to address this substantial set of issues we're encountering. I'll be duplicating this message across all similar issues we're facing.

@AndriiSherman
Copy link
Member

Fixed in drizzle-orm@0.30.0

Please check release notes for more info

@stabildev
Copy link

I'm still facing this issue (partially) in 0.33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants