Skip to content

Instantly share code, notes, and snippets.

@wilig
Created August 7, 2010 17:29
Show Gist options
  • Select an option

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

Select an option

Save wilig/513003 to your computer and use it in GitHub Desktop.
(defn collect*
[table & xs]
(if (vector? (last xs))
(let [tbls (interpose ", " (map #(sqlize %) (conj (butlast xs) table)))
cols (str-utils/str-join ", " (map #(sqlize %) (last xs)))]
(apply str "select " cols " from " tbls))
(let [tbls (interpose ", " (map #(sqlize %) (conj xs table)))]
(apply str "select * from " tbls))))
(defmacro collect
[table & xs]
`(let [~'as (fn[name# col#] (str (sqlize col#) " AS " (sqlize name#)))]
(collect* ~table ~@xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment