From 3abe6a104f3bccafdf6f6aabefc107582b509770 Mon Sep 17 00:00:00 2001 From: Stathis Sideris Date: Sat, 21 Jun 2014 13:23:02 +0100 Subject: [PATCH 1/2] Updated readme to reflect the fact that insert, update, delete are already implemented. --- README.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9eb5736..870d134 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,40 @@ To add to clauses instead of replacing them, use `merge-select`, `merge-where`, => ["SELECT a, b, c, d, e FROM foo WHERE (f.a = ? AND b > 10)" "baz"] ``` +Inserts are supported: + +```clj +(-> (insert-into :properties) + (columns :a :b :c :d) + (values + [[1 2 3 4 5] + [6 7 8 9 10] + [11 12 13 14]]) + sql/format) +=> ["INSERT INTO properties (a, b, c, d) VALUES (1, 2, 3, 4, 5), (6, 7, 8, 9, 10), (11, 12, 13, 14)"] +``` + +Updates are possible too (note the double S in `sset` to avoid clashing +with `clojure.core/set`): + +```clj +(sql/format + (-> (update :films) + (sset {:kind "dramatic" + :watched true}) + (where [:= :kind "drama"]))) +=> ["UPDATE films SET watched = TRUE, kind = ? WHERE kind = ?" "dramatic" "drama"] +``` + +Deletes look as you would expect: + +```clj +(sql/format + (-> (delete-from :films) + (where [:<> :kind "musical"]))) +=> ["DELETE FROM films WHERE kind <> ?" "musical"] +``` + Queries can be nested: ```clj @@ -230,7 +264,6 @@ If you do implement a clause or function handler, consider submitting a pull req ## TODO -* Insert, update, delete * Create table, etc. ## License From e283c1437ed6c270f5c3327dac17746c9062de4e Mon Sep 17 00:00:00 2001 From: Stathis Sideris Date: Sat, 21 Jun 2014 15:14:46 +0100 Subject: [PATCH 2/2] Better examples --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 870d134..185f532 100644 --- a/README.md +++ b/README.md @@ -83,33 +83,35 @@ Inserts are supported: ```clj (-> (insert-into :properties) - (columns :a :b :c :d) + (columns :name :surname :age) (values - [[1 2 3 4 5] - [6 7 8 9 10] - [11 12 13 14]]) + [["Jon" "Smith" 34] + ["Andrew" "Cooper" 12] + ["Jane" "Daniels" 56]]) sql/format) -=> ["INSERT INTO properties (a, b, c, d) VALUES (1, 2, 3, 4, 5), (6, 7, 8, 9, 10), (11, 12, 13, 14)"] +=> ["INSERT INTO properties (name, surname, age) + VALUES (?, ?, 34), (?, ?, 12), (?, ?, 56)" + "Jon" "Smith" "Andrew" "Cooper" "Jane" "Daniels"] ``` Updates are possible too (note the double S in `sset` to avoid clashing with `clojure.core/set`): ```clj -(sql/format - (-> (update :films) - (sset {:kind "dramatic" - :watched true}) - (where [:= :kind "drama"]))) +(-> (update :films) + (sset {:kind "dramatic" + :watched true}) + (where [:= :kind "drama"]) + sql/format) => ["UPDATE films SET watched = TRUE, kind = ? WHERE kind = ?" "dramatic" "drama"] ``` Deletes look as you would expect: ```clj -(sql/format - (-> (delete-from :films) - (where [:<> :kind "musical"]))) +(-> (delete-from :films) + (where [:<> :kind "musical"]) + sql/format) => ["DELETE FROM films WHERE kind <> ?" "musical"] ```