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:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.