5 ms·
Ecto really hits the sweet spot. Usually, there are two camps on data accessing: 1. Anti-ORM because object-relational impedance mismatch: ORM will always be
by namelosw 5y ago
Ecto really hits the sweet spot.
Usually, there are two camps on data accessing:
1. Anti-ORM because object-relational impedance mismatch: ORM will always be a leaky abstraction, and it introduces its own learning curve and mental overhead.
2. Pro-ORM: despite the impedance mismatch, the alternatives usually suck when it comes to writing: The boilerplate, the ad-hoc-ness. Very often people would use query builders to build yet another leaky abstraction so ORM seems to be the necessary evil.
Meanwhile Ecto:
1. It's one of the best query builders on the market. Thanks to Elixir macros, it's very flexible and you can just use functions to parameterize and reuse them very easily.
2. It's not an ORM but there's also a Schema as a shorthand counterpart for regular things.
3. By the way, it doesn't lazy load so n+1 is not a problem anymore.
- realusername 5y agoI would also mention the changesets which are the best way to represent data changes, it's so useful that I use it outside of databases. The main issue for me with ecto is the lack of helpers with mass inserts, thinks like activerecord import & in_batches of activerecord would be nice.
- nesarkvechnep 5y agoBut there’s Multi which is useful in a lot of cases.
- louissm_it 5y agoChangesets are such a great idea, I always find myself trying to replicate them when working in other environments. If anyone is interested, I found this article showing how to use changesets outside the database: https://elixirfocus.com/posts/ecto-schemaless-changesets/ https://elixirfocus.com/posts/ecto-schemaless-changesets/
- yoran 5y agoI agree. I adopted changesets in my Rails codebase after having used them in Phoenix.