SQL DSL’s in other languages

Like jOOQ, there are many other tools out there, that aim to implement SQL as an internal DSL in other languages. This one is particularly nice-looking. It’s called sqlkorma, a SQL DSL for Clojure. A sample SQL statement taken from their documentation:

(select users
  (with address) ;; include other entities based on
                 ;; their relationship
  (fields :first :last :address.state)
      ;; you can alias a field using a vector of [field alias]
  (aggregate (count :*) :cnt :status) 
      ;; You specify alias and optionally a field to group by
      ;; available aggregates:
      ;; sum, first, last, min, max, avg, count
  (where {:first "john"
          :last [like "doe"]}) 
  (order :id :ASC)
  (group :status)
  (limit 3)
  (offset 3))

These nice languages that support closures and/or lambda expressions make for much more intuitive aliasing than jOOQ can do today. I’m really looking forward to Java 8!

See more examples in the documentation:

http://sqlkorma.com/docs#db