Skip to content

Instantly share code, notes, and snippets.

@spariev
Created June 21, 2010 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spariev/446863 to your computer and use it in GitHub Desktop.
Save spariev/446863 to your computer and use it in GitHub Desktop.
(defmacro execute-query
"Wrapper around with-connection & with-query-results"
[results query & body]
`(do
(debug (str "[SQL] " ~query))
(with-connection {:datasource (data-source)}
(with-query-results ~results [~query] ~@body))))
(defmacro with-items-in
[ids options & body]
`(let [ids-cond# (str-utils2/join "," ~ids)
query# ~(options :query)
table# ~(options :table)]
(do
(info ~(options :msg))
(execute-query
`items
(str query#
" WHERE " table# ".id IN (" ids-cond#
") GROUP BY " table# ".id ORDER BY NULL")
~@body))))
;; with `items at line 17 it gives
;; Unsupported binding form: (quote tm.search.utils/items)
;; and with quote removed I receive
;; Can't use qualified name as parameter: tm.search.utils/items
;; [Thrown class java.lang.Exception]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment