(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))