Skip to content

Instantly share code, notes, and snippets.

@wilig
Created August 18, 2010 17:50
Show Gist options
  • Save wilig/535586 to your computer and use it in GitHub Desktop.
Save wilig/535586 to your computer and use it in GitHub Desktop.
(defmacro order-by
[& forms]
(let [sorts (butlast forms)
query (last forms)]
`(let [~'asc (fn[x# & xs#] (str (str-utils/str-join ", " (map sqlize (conj xs# x#))) " ASC"))
~'desc (fn[x# & xs#] (str (str-utils/str-join ", " (map sqlize (conj xs# x#))) " DESC"))]
(let [ob# [~@sorts]]
(merge-with concat ~query (stmt (str " ORDER BY " (str-utils/str-join ", " ob#))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment