What ORMs have taught me: just learn SQL
I used to write raw SQL for many years, then, around 2005 switched over to ORMs in order to be able to target different databases, have a nice model, etc. Lets be honest here, the ease of justing doing:<p><pre><code>    p.username = "Carl"
    p.age = 33
    p.save
</code></pre>
instead of "update users set username=:username, age=:age where id=:id" has a ton of advantages. For one, some sort of syntax or type checker is actually trying to understand your queries and makes it easy to find typos <i>before</i> the database laments in the middle of a huge transaction. Strongly typed languages are even cooler here (most notably Slick for Scala, which has a fully type-checked DSL for database querying which makes it really difficult to create typos) [1].<p>However, the downside of this is that it only works as long as whatever you need from your database is the lowest common denominator of database features. I'm currently working on a Clojure + Postgres project and I'm using all the bells & whistles that Postgres has to offer: HStore types, Json Types, subqueries in subqueries, Upserts, functions, etc. I have a rather complex database that I'm running analytical queries against, and using an ORM for this would simply not work. I'd spend half my time trying to figure out how to implement a certain Postgres feature in -insert-or-name-here. I actually started with Korma [2], a simple Clojure ORM, and gave up because it was too tedious trying to figure out how to get it to correctly run my 4-function column result query.<p>I've since switched to YeSQL [3] which follows a very interesting idea: You write queries in .sql files (full editor support, jay) and tag every query with a name. YeSQL then reads these .sql files during compile time and dynamically generates clojure functions with the correct amount of parameters based on these queries. It is kinda the best of both worlds. Example:<p>queries.sql:<p><pre><code>    -- name: get-users
    -- a function to retrieve the user by name
    select * from users where username=:name
</code></pre>
clojure.clj:<p><pre><code>    (defqueries "some/where/queries.sql")

    ;; now I can do:
    (get-users "carl")
</code></pre>
I think it really depends on the use case. If the database model is simple and there're no crazy database technologies in use, I'd rather go and use an ORM again I guess.<p>[1] <a href="http://slick.typesafe.com/" rel="nofollow">http://slick.typesafe.com/</a>
[2] <a href="http://sqlkorma.com/" rel="nofollow">http://sqlkorma.com/</a>
[3] <a href="https://github.com/krisajenkins/yesql" rel="nofollow">https://github.com/krisajenkins/yesql</a>