Better examples

This commit is contained in:
Stathis Sideris 2014-06-21 15:14:46 +01:00
parent 3abe6a104f
commit e283c1437e

View file

@ -83,33 +83,35 @@ Inserts are supported:
```clj ```clj
(-> (insert-into :properties) (-> (insert-into :properties)
(columns :a :b :c :d) (columns :name :surname :age)
(values (values
[[1 2 3 4 5] [["Jon" "Smith" 34]
[6 7 8 9 10] ["Andrew" "Cooper" 12]
[11 12 13 14]]) ["Jane" "Daniels" 56]])
sql/format) 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 Updates are possible too (note the double S in `sset` to avoid clashing
with `clojure.core/set`): with `clojure.core/set`):
```clj ```clj
(sql/format (-> (update :films)
(-> (update :films) (sset {:kind "dramatic"
(sset {:kind "dramatic" :watched true})
:watched true}) (where [:= :kind "drama"])
(where [:= :kind "drama"]))) sql/format)
=> ["UPDATE films SET watched = TRUE, kind = ? WHERE kind = ?" "dramatic" "drama"] => ["UPDATE films SET watched = TRUE, kind = ? WHERE kind = ?" "dramatic" "drama"]
``` ```
Deletes look as you would expect: Deletes look as you would expect:
```clj ```clj
(sql/format (-> (delete-from :films)
(-> (delete-from :films) (where [:<> :kind "musical"])
(where [:<> :kind "musical"]))) sql/format)
=> ["DELETE FROM films WHERE kind <> ?" "musical"] => ["DELETE FROM films WHERE kind <> ?" "musical"]
``` ```