3 ms·
I actually find composed queries and the associated "bureaucracy" a little annoying in Ecto. The convention seems to be to put pure "query components" in your
by dudul 6y ago
I actually find composed queries and the associated "bureaucracy" a little annoying in Ecto. The convention seems to be to put pure "query components" in your schema, to call them from your context to build the actual query you want to send to your Repo.
The problem with that is that it becomes a bit harder to parse what the query actually is, which columns are effectively involved, and which indices to you want to create to make sure they support it. This is somewhat similar to what's briefly mentioned in a recent post by Sasa Juric: https://medium.com/very-big-things/towards-maintainable-elixir-the-core-and-the-interface-c267f0da43 https://medium.com/very-big-things/towards-maintainable-elix...
Another thing is that I really wish they would find a way to make it more obvious/easier to understand that `Changeset` is a formidable tool for pure data validation, without necessarily involving a DB, or even a Schema.
Other than that, it's a great tool :)
- ch4s3 6y agoI think the balance between reusable and composable query components and readable queries will depend on your use case. If you find a composed query too hard to read, you should probably do less of the query building in functions. I find decomposing into small functions is most useful when the query needs to come together dynamically.
- senjin 6y agoI completely agree about changesets. I wish they would extract that into it's own project that ecto uses. Seems like a lot of work to make it general enough but using it for form validation has worked out really well and I think using them for that case should be a more first class citizen in phoenix.
- sodapopcan 6y agoWhat you're describing is really no different than ActiveRecord scopes. The difference is is that Rails will silently do an N+1. I do agree about Changesets—they took me quite a while to grok, but I really like them now.