by eric4smith · 5y ago · 0 comments
Recently I had to stand up a quick elixir project and decided to write all queries by hand and not use Ecto.
It was extremely enjoyable writing every query from the start. Just thinking carefully about what columns I needed, and crafting the best joins and where clauses made efficiency baked in from the beginning.
If one is not careful and just be lazy with an ORM you get back all columns all the time - and this is the biggest sin of an ORM. Not to mention sub-optimal where clauses that kill performance.
And the next positive side effect was the amazing speed of the database interactions in the app.
It’s not something I’d do all the time since sometimes you do need the discipline of Ecto, but I say we should write more sql by hand instead of less.
The “not careful and just be lazy” way won’t get you in a good place whatever approach you take.
Are you not afraid that your queries will have SQL injections? Or handle unicode poorly, binary blobs, etc?
> you get back all columns all the time
I think this is why you can map multiple schemas to the same table in Ecto