/
update_test.clj
35 lines (30 loc) · 1.5 KB
/
update_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(ns seaquell.update-test
(:refer-clojure
:exclude [alter distinct drop group-by into set update partition-by when])
(:require [midje.sweet :refer :all :exclude [after before]]
[seaquell.core :refer :all]))
(facts "about update"
;; simple update
(update$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE tbl SET a=1, b=2 WHERE c > 5;"
;; using INDEXED BY
(update$ :tbl (not-indexed) (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE tbl NOT INDEXED SET a=1, b=2 WHERE c > 5;"
(update$ :tbl (indexed-by :ix) (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE tbl INDEXED BY ix SET a=1, b=2 WHERE c > 5;"
(update$ :tbl :indexed-by :ix :set {:a 1 :b 2} :where {:c [> 5]})
=> "UPDATE tbl INDEXED BY ix SET a=1, b=2 WHERE c > 5;"
;; alternate verbs
(update-or-rollback$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE OR ROLLBACK tbl SET a=1, b=2 WHERE c > 5;"
(update-or-abort$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE OR ABORT tbl SET a=1, b=2 WHERE c > 5;"
(update-or-replace$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE OR REPLACE tbl SET a=1, b=2 WHERE c > 5;"
(update-or-fail$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE OR FAIL tbl SET a=1, b=2 WHERE c > 5;"
(update-or-ignore$ :tbl (set {:a 1 :b 2}) (where {:c [> 5]}))
=> "UPDATE OR IGNORE tbl SET a=1, b=2 WHERE c > 5;")
(fact "update is idempotent"
(update (update :tbl (set {:a 1 :b 2}) (where {:c [> 5]})))
=> (update :tbl (set {:a 1 :b 2}) (where {:c [> 5]})))