Skip to content

Commit

Permalink
Return PostgreSQL decimals as numbers not strings
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-3906
https://eaflood.atlassian.net/browse/WATER-3927

With our [Add billing_transaction model to water-abstraction-system](#135) change we had our first decimal field.

What we didn't realise when we created the migration is that the [pg package](https://www.npmjs.com/package/pg) returns decimals as strings.

We've encountered this issue before with BigInt's on the [charging-module-api](https://github.com/DEFRA/sroc-charging-module-api) which is why `db/db.js` has logic to parse the string **pg** returns back into a integer.

The root cause is the same. Out of concern about loss of precision the DB values are returned as strings. We know we're not dealing with values where this would be an issue so we can have **pg** implicitly parse the decimal strings into floats.

[This post](https://stackoverflow.com/a/39176670/6117745) focuses on the BigInt issue. But the cause and solution are the same for decimals.

So, this change ensures when we use [Knex](https://github.com/knex/knex) or [Objection.js](https://github.com/vincit/objection.js) we see floats (numbers) instead of strings.
  • Loading branch information
Cruikshanks committed Mar 5, 2023
1 parent 4fe82ec commit e28314f
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit e28314f

Please sign in to comment.