kipcole9 / money

Elixir implementation of Money with Currency

Home Page:https://hex.pm/packages/ex_money

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Separation of core and sql

svarlet opened this issue · comments

Hi!

First of all, thanks for this library. It looks like you know what you're doing on a problem that is underestimated by 101% of engineers. The Readme is exhaustive and testify that you put a lot of care into it.

Now, to my small issue in comparison to the problem tackled here, would you consider splitting this lib in 2+ packages? I'm thinking that I may want to use the core of the library without embedding things like Ecto, SQL, Postgres, Phoenix.HTML, Plug, ...

Seb

Thanks for the kind words, its appreciated. I also think is a good suggestion. Splitting out the serialisation code (Ecto + database types) makes a lot of sense. It also would then follow Ecto's strategy of extracting the sql part into ecto_sql.

Phoenix.HTML is an optional dependency which, if included, only adds a protocol implementation so it shouldn't be present unless you specifically include it in mix.exs.

The plug implementations come from ex_cldr and is therefore in the localisation layer. Repackaging ex_cldr isn't currently on my radar but it is worth considering for a future release.

So I think the approach would be to split ex_money into ex_money and ex_money_ecto. Since that would be a breaking change it would need to be a major release. Thoughts?

I also had the Ecto split in mind when I suggested it. I was one of many advocates of this change in Ecto as well.

With regards to the package name, I think it makes sense. I wonder if _ecto is the most flexible suffix though. Over time, if you were to swap the dependency on ecto by something else, the name of the lib and repo would need to change as well. Perhaps more likely, if you were to support an extra library, the name would not be accurate anymore. I think a name reflecting the "what" instead of the "how" is likely to cause less trouble and remain accurate. An example would be ex_money_sql.

Yes, it makes sense to use ex_money_sql. I'll refactor over the weekend into two repos and report back here.

Excellent!

Split and published:

Great, thanks!

Any guide or gotchas re: upgrading from ex_money 3.x -> ex_money 4 + ex_money_sql 1?

The changelog is quite clear but no tips re: upgrading -- I just upgraded ex_money + installed ex_money_sql and everything seems to be working fine so far

Thanks a ton for the great software :]

Oh... I see that now my custom :money type for Absinthe now returns:

"amount": {
            "sign": 1,
            "exp": 0,
            "coef": 27
          }

Went from Money 3.2 -> 4 + sql... I guess I missed something in the docs 🤣

@njwest Thats surprising! The package split is literally that (I will update the docs on migration) so that adding the two packages should produce identical results.

I've not done any work with Absinthe but I will run some more tests with Ecto to see if I can find the issue.

If the issue is still valid would you mind opening a new issue so I can track it properly?

Maybe as part of the update decimal was updated causing the difference?