What is the typical way to persist currency? #494
-
I understand that I can rely on the currencies not to change, unless upgrading to a breaking change version of dinero. But what is the typical way to persist the currency of a dinero object, like in a database, so it can be retrieved later and also insured that the appropriate currency exponent and base always be used? Should the whole snapshot of the dinero object be persisted, with its currency, to ensure its value is always interpreted correctly? CREATE TABLE "ExampleAmount" (
"amount" INTEGER,
"code" VARCHAR(3);
"base" INTEGER,
"exponent" INTEGER,
"scale" INTEGER
); I get that all applications will have different needs, but I just want to make sure I am on the right track, and not over thinking it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @johnhooks!
What the documentation means is that, if a currency changes (for example, if the U.S. dollar suddenly becomes 1000 cents in a dollar), changing it in Dinero.js is a breaking change in nature, which is why there's a different importing strategy to avoid breakages.
There's a whole guide on this topic. It's good practice to store a full snapshot of Dinero objects in database, which is why the API exposes a |
Beta Was this translation helpful? Give feedback.
Hey @johnhooks!
What the documentation means is that, if a currency changes (for example, if the U.S. dollar suddenly becomes 1000 cents in a dollar), changing it in Dinero.js is a breaking change in nature, which is why there's a different importing strategy to avoid breakages.
There's a whole guide on this topic. It's good practice to store a full snapshot of Dinero o…