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]: Wrong data type for postgres date colum #1407

Closed
PhilippDehler opened this issue Oct 24, 2023 · 8 comments · Fixed by #1659
Closed

[BUG]: Wrong data type for postgres date colum #1407

PhilippDehler opened this issue Oct 24, 2023 · 8 comments · Fixed by #1659
Assignees
Labels
bug Something isn't working

Comments

@PhilippDehler
Copy link

What version of drizzle-orm are you using?

0.27.2

What version of drizzle-kit are you using?

0.19.9

Describe the Bug

Hey,

First of all, we'd like to express our enthusiasm for using Drizzle - it's an awesome tool. However, we have encountered a bug that requires attention.

We created a pgTable with a date column in TypeScript, as shown below:

const SomeDateModel = pgTable("some_data_model", {
  id: serial("id").primaryKey(),
  date: date("date").notNull(),
});

 type SomeDateModel = InferModel<typeof SomeDateModal>; //type SomeDateModel = { id:number; date:string }

The issue we've encountered is that TypeScript is reporting an unexpected data type. It expects a string but receives a date in the result. For instance:

const someDateResult = await client.query.someDateModel.findFirst() // { id:1, date: 2023-10-24T00:00:00.000Z }

Expected behavior

I would expect either a string like '2023-01-01' or the proper Date-type in the infered model

Environment & setup

We are using:
"node": "18.14.0",
"pnpm": "8.6.0",
"drizzle-orm": "0.27.2".
"drizzle-kit": "0.19.9"

@arxpoetica
Copy link

arxpoetica commented Nov 21, 2023

I'm hitting this bug. I ended up doing:

date: sql`to_char(${transactions.date}, 'YYYY-MM-DD')`,

@Angelelz Angelelz self-assigned this Dec 15, 2023
@SkaceKamen
Copy link

I've had the same issue, specifying mode: "date" at least provides proper type:

birthDate: date('birth_date', { mode: 'date' }),

This doesn't change the behaviour, but fixes the incorrect type. Using mode: "string" doesn't fix the issue.

@Hebilicious
Copy link

@Angelelz this should be fixed as well right ?

@Angelelz
Copy link
Collaborator

Give it a try in the beta tag and let me know

@ArjobanSingh
Copy link

Hi @Angelelz,
I installed 0.29.4-d783960 beta version and bug is fixed in that, but not yet fixed in main 0.29.4 version though. Is it something which will be released in next version?

@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.

@PhilippDehler
Copy link
Author

I tried it and it is fixed.

@AndriiSherman
Copy link
Member

Fixed in drizzle-orm@0.30.0

Please check release notes for more info

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
7 participants