Skip to content

Instantly share code, notes, and snippets.

@wilig
Created August 8, 2010 01:34
Show Gist options
  • Select an option

  • Save wilig/513438 to your computer and use it in GitHub Desktop.

Select an option

Save wilig/513438 to your computer and use it in GitHub Desktop.
(defmacro filter
[pred query]
`(let [~'and (fn[& xs#] (apply str (interpose " AND " xs#)))
~'or (fn[& xs#] (apply str (interpose " OR " xs#)))
~'= (fn[x# y#] (sql-exp "=" x# y#))
~'> (fn[x# y#] (sql-exp ">" x# y#))
~'< (fn[x# y#] (sql-exp "<" x# y#))
~'like (fn[x# y#] (sql-exp "like" x# y#))
~'in (fn[x# xs#]
(str (sqlize x#) " IN (" (apply str (interpose ", " xs#)) ")"))]
(apply str ~query " where " ~pred)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment