3 ms·
Your description is a bit hard to follow, but it smells kind of like something Ecto schemas could deal with? That is, by defining an Ecto schema for your data
by jkhdigital 5y ago
Your description is a bit hard to follow, but it smells kind of like something Ecto schemas could deal with?
That is, by defining an Ecto schema for your data structure you can go almost directly from raw json to clean, correctly casted data.
To use an example similar to yours, this is how I process data from cryptocurrency exchange APIs—just write up a schema for the shape of the response, parse the json into a map and throw the map into Ecto.Changeset.cast. Even if everything is a string in the raw data, it will be correctly cast into integer/float/whatever as defined in the schema.
- arthurcolle 5y agoSorry about that. Vacationing in Miami Beach right now so I might not be 100% in my descriptive capacity. Anyways, yeah, that obviously could work, but I'm kind of trying to make this all just run in memory because I'm already persisting all the data separately.
- jkhdigital 5y agoYou can use Ecto schemas and changesets without a database! It is an incredibly useful library, once you get over the somewhat steep learning curve.
- jolux 5y agoHuh, TIL. Will have to look into that. Do you have any blog posts handy that explain this?
- dnautics 5y agohttps://speakerdeck.com/gvaughn/ecto-without-a-db-many-meanings-of-map https://speakerdeck.com/gvaughn/ecto-without-a-db-many-meani...
- jolux 5y agoThanks!
- arthurcolle 5y agoThanks for your reply to my original comment. I hadn’t considered Ecto, but I guess it does make sense to think of the ChangeSet abstraction irrespective of whether or not you are persisting the data in question. Appreciate it. Do you have an email or something so we could chat further?