summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--src/clojure_sql/compiler.clj2
-rw-r--r--src/clojure_sql/core.clj30
3 files changed, 29 insertions, 6 deletions
diff --git a/README.md b/README.md
index 6e82200..b83479e 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,8 @@ queries to be entirely special-cased per database. By default
-[clojure.java.jdbc][3] support is provided, but must be included explicitly.
+[`clojure.java.jdbc`][3] support is provided, but must be included
+explicitly. `clojure-sql` does not depend on `clojure.java.jdbc`.
(require '[clojure-sql.jdbc :as jdbc])
diff --git a/src/clojure_sql/compiler.clj b/src/clojure_sql/compiler.clj
index 0cbb808..6b3ec4a 100644
--- a/src/clojure_sql/compiler.clj
+++ b/src/clojure_sql/compiler.clj
@@ -258,7 +258,7 @@
(table-name db (val (first tables)))
" ("
(->> fields
- (map (comp (partial table-name db) second val))
+ (map (comp (partial field-name db) second val))
(string/join ","))
") VALUES (" (string/join "),(" %) ")")
build-insertion #(->> (for [field fields-order]
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj
index 81c9c13..97cee93 100644
--- a/src/clojure_sql/core.clj
+++ b/src/clojure_sql/core.clj
@@ -41,21 +41,43 @@
(pr (c/compile-select *database-type* query))))
-(defn run-query [query]
+(defn run-query
+ "Run a select query. Return value is determined by query executor."
+ [query]
(assert *query-executor* "Cannot execute a query without a query executor")
(*query-executor* :select (c/compile-select *database-type* query)))
-(defn insert! [query & records]
+(defn insert!
+ "Insert a number of records into a table, setting each column to the
+ corresponding value from the record. Return value is determined by
+ query executor."
+ [query & records]
(assert *query-executor* "Cannot execute a query without a query executor")
(let [compiled (apply c/compile-insert *database-type* query records)]
(*query-executor* :insert compiled)))
-(defn update! [query partial-record]
+(-> (table :x)
+ (project {:id :uid})
+ (insert! {:uid 10}))
+
+(defn update!
+ "Update everything which would have been selected by the query,
+ setting each field in the query to the corresponding column in the
+ table. Return value is determined by query executor.
+
+ NOTE: if the map does not have a given key then this will result in
+ a NULL being included in the query. To avoid this restrict the query
+ with `project` before calling `update!`."
+
+ [query partial-record]
(assert *query-executor* "Cannot execute a query without a query executor")
(let [compiled (c/compile-update *database-type* query partial-record)]
(*query-executor* :update compiled)))
-(defn delete! [query]
+(defn delete!
+ "Delete everything which would have been selected by the
+ query. Return value is determined by query executor."
+ [query]
(assert *query-executor* "Cannot execute a query without a query executor")
(let [compiled (c/compile-delete *database-type* query)]
(*query-executor* :delete compiled)))