bojanz / currency

Currency handling for Go.

Home Page:https://pkg.go.dev/github.com/bojanz/currency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoSql Support

erotokritosVall opened this issue · comments

Are there any plans to support storing Amount in no-sql databases? (for example mongo)

If not do you have any tips on how to store that info? (mostly the number part concerns me)

MongoDB appears to have a decimal type you can use for the number part: https://www.mongodb.com/docs/manual/tutorial/model-monetary-data/#std-label-numeric-decimal

Happy to include a MongoDB example in https://github.com/bojanz/currency/wiki/Database-integration-notes if you can provide one.

You are right, but I was wondering if there is built-in support for it

I solved the problem by storing the number as int64
I know it is not entirely correct but it will suffice for my use case

Using an int64 is a fine workaround for most systems. Still, you should be able to do something like this when storing the amount:

d, err := primitive.ParseDecimal128(a.Number())