summaryrefslogtreecommitdiff
path: root/src/clojure_sql/query.clj
blob: 113e748202c33f689d6f8a97d19ef1944e8fd688 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(ns clojure-sql.query)

(defprotocol QueryExecutor
  (query [_ query]
    "Retrieve information from the database.")
  (insert! [_ query records]
    "Insert a number of records into a table, setting each column to the corresponding value in its record.")
  (update! [_ query partial-record] 
    "Update every row which this query would select by setting each field to the corresponding value in partial-record.")
  (delete! [_ query]
    "Delete every row which this query would select."))

(defn fn->QueryExecutor [f]
  (reify QueryExecutor
    (query [_ query] ())))

(defrecord ^:private Query [executor]
  clojure.lang.IDeref
  (deref [this]
    (assert executor "Cannot deref a query without a query executor")
    (query executor this)))

(def query? (partial instance? Query))