View difference between Paste ID: brxfRZHS and 15wd0m9d
SHOW: | | - or go back to the newest paste.
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-
; NOT SURE WHAT I'M DOING HERE
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))))
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"))