| The basic problem is that: 1) Relational databases are the best abstraction we've found for storing data. Despite years of attempts (OODB, XML databases, various nosql stores, etc.), we have not been able to improve on it. postgresql, by adding native JSON support, became a better mongo than mongo virtually overnight. 2) Most people never learn databases, and most people who do are idiots working on enterprise three-tier architectures, so mostly it's misused. There is an attempt to hide them. 3) ORMs generally make easy stuff easy, and hard stuff painful. What I generally want is: 1) Something translating SQL syntax into my native language, but maintaining SQL full semantics and expressiveness. 2) This should allow me to be database-agnostic. 3) This should prevent things like injection attacks. 4) It should not map onto objects. It should maintain 100% of the capability of SQL. The only differences should be syntactic (e.g. instead of writing WHERE, I might write .where() or similar). 5) This may and ideally should have added functionality, for example, around managing and organizing database migrations. Stored procedures and virtual tables are also very important (but poorly implemented in most databases). These: 1) Allow proper abstraction at the SQL level. 2) Improve performance. What most programmers fail to understand -- since universities don't teach -- is how powerful and elegant the underlying theory of databases is. |
The huge win was that I could use the Clojure REPL to run my SQL-generating functions and see that the SQL actually matched what I was aiming for. Caching the query-building was as simple as memoizing the query building functions as queries are parameterised in any case, so can be reused.
There is something really nice about having the full power of SQL at your fingertips. The only drawback compared to ORMs of course is that it outputs the resulting query result in a flat structure. So any aggregation you'd need to handle in code or use something like Postgres JSON aggregation.
[1] https://github.com/seancorfield/honeysql