drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.57k stars 490 forks source link

[BUG]: Numeric column is returned as float instead of string when using 'with' #1453

Open cloleb opened 8 months ago

cloleb commented 8 months ago

What version of drizzle-orm are you using?

0.28.6

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

When including a relationship in a query using 'with', if the relationship (children table) contains a numeric field, the numeric field is returned as a float instead of a string, removing all precision on the numeric.


Example

the following query:

const query = await db.query.tableA.findOne({ with: { tableB: true } })

will return something like this:

{id:1, tableB: {id: 1, amount: 2.3}}

instead of this:

{id:1, tableB: {id: 1, amount: '2.30'}}


Important note

This problem only occurs when selecting/including tableB in a query using 'with'. Querying tableB directly like this:

await db.query.tableB.findOne()

will return the following (which is correct):

{id: 1, amount: '2.30'}

Expected behavior

Numerics should be returned as strings when using 'with'

Environment & setup

Postgres (node-postgres)

cloleb commented 8 months ago

https://github.com/drizzle-team/drizzle-orm/issues/1042#issuecomment-1722551657

AlekStudioIntellisoft commented 7 months ago

Same here, breaking many things. Any news?