3 ms·
I've been pretty happy with Elixir's Ecto. I wouldn't call it easy, though. There is a LOT of ceremony, but it's designed to be declarative and it sure puts m
by dnautics 6y ago
I've been pretty happy with Elixir's Ecto. I wouldn't call it easy, though. There is a LOT of ceremony, but it's designed to be declarative and it sure puts me at ease.
For database ingress, I use schemas, and put in aggressive validations in the changesets. For jsonb values, I use embedded_schemas (https://thoughtbot.com/blog/embedding-elixir-structs-in-ecto-models https://thoughtbot.com/blog/embedding-elixir-structs-in-ecto...), and cast their creation as a normal part of filling in the database object. For egress to a third party that accepts JSON, I use naked embedded_schemas (even better if they can be shared with the database) and use a protocol to build an custom encoder that can for example send the 3rd party a deeply structured JSON from a flat struct. Due to the way protocols work in elixir, when I send it to Oauth, Oauth will (indirectly) call my protocol code.
- waynesonfire 6y agoThis sounds pretty sweet, do you happen to have any resources handy that dive deeper into these concepts?
- dnautics 6y agounfortunately it's not super well documented. Some of the concepts are a bit new (~2 yrs or so), and I kind of stumbled into this as a best practice by accident literally in the last two months when I had to do this for work and was like, "oh, this is a thing". This video helped: https://www.youtube.com/watch?v=k_xDi7zAcNM https://www.youtube.com/watch?v=k_xDi7zAcNM