Advertisement
Guest User

Untitled

a guest
Jun 26th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns shouter.models.mark
  2.   (:require [clojure.java.jdbc :as sql]))
  3.  
  4. (defmacro with-conn [form]
  5.   (list 'sql/with-connection (System/getenv "DATABASE_URL") form))
  6.  
  7. (defn all []
  8.   (with-conn
  9.     (sql/with-query-results results
  10.       ["select * from marks order by id desc"]
  11.       (into [] results))))
  12.  
  13. (defn one [id]
  14.   (with-conn
  15.     (sql/with-query-results results
  16.       [(str "select * from marks where id = " id)]
  17.       (first (into [] results)))))
  18.  
  19. ; I'm trying to make a macro like below
  20. (defmacro get-results [query]
  21.   (list 'with-conn (list 'sql/with-query-results results [query] (into [] results))))
  22.  
  23. ; So that I can call something like this
  24. (defn all []
  25.   (get-results "select * from marks"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement