(seq->batch-params xs)convert seq of seqs to updatable values (to use in SQL batch updates):
=> ;; xs [[#uuid 'c7a344f2-0243-4f92-8a96-bfc7ee482a9c' #uuid 'b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa'] [#uuid '3236ebed-8248-4b07-a37e-c64c0a062247' #uuid 'b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa']]
=> (seq->batch-params xs)
('c7a344f2-0243-4f92-8a96-bfc7ee482a9c','b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa'),
('3236ebed-8248-4b07-a37e-c64c0a062247','b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa')
to be able to plug them into something like:
update test as t set
column_a = c.column_a
from (values
('123', 1), << here
('345', 2) << is a batch of values
) as c(column_b, column_a)
where c.column_b = t.column_b;
convert seq of seqs to updatable values (to use in SQL batch updates):
=> ;; xs
[[#uuid 'c7a344f2-0243-4f92-8a96-bfc7ee482a9c'
#uuid 'b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa']
[#uuid '3236ebed-8248-4b07-a37e-c64c0a062247'
#uuid 'b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa']]
=> (seq->batch-params xs)
('c7a344f2-0243-4f92-8a96-bfc7ee482a9c','b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa'),
('3236ebed-8248-4b07-a37e-c64c0a062247','b29bc806-7db1-4e0c-93f7-fe5ee38ad1fa')
to be able to plug them into something like:
update test as t set
column_a = c.column_a
from (values
('123', 1), << here
('345', 2) << is a batch of values
) as c(column_b, column_a)
where c.column_b = t.column_b;
safety first
safety first
(to-sql-string this)trusted type will be SQL'ized
trusted type will be SQL'ized
(with-preds query pred-map)(with-preds query pred-map {:keys [prefix]})=> (q/with-preds "select foo from bar where this = that" {#(= 42 42) "and dog = :bow" #(= 2 5) "and cat = :moo" #(= 28 28) "or cow = :moo"})
=> "select foo from bar where this = that and dog = :bow or cow = :moo"
;; or with "where":
=> (q/with-preds "select foo from bar" {#(= 42 42) "and dog = :bow" #(= 2 5) "and cat = :moo" #(= 28 28) "or cow = :moo"} {:prefix "where"})
=> "select foo from bar where dog = :bow or cow = :moo"
* adds predicates to the query
* if "where" needs to be prefixed add {:prefix "where"}
* will remove any SQL ops that a predicate starts with in case it needs to go right after "where"
* if none preds matched with "where" prefix the prefix won't be used
=> (q/with-preds "select foo from bar where this = that"
{#(= 42 42) "and dog = :bow"
#(= 2 5) "and cat = :moo"
#(= 28 28) "or cow = :moo"})
=> "select foo from bar
where this = that
and dog = :bow
or cow = :moo"
;; or with "where":
=> (q/with-preds "select foo from bar"
{#(= 42 42) "and dog = :bow"
#(= 2 5) "and cat = :moo"
#(= 28 28) "or cow = :moo"}
{:prefix "where"})
=> "select foo from bar
where dog = :bow
or cow = :moo"
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |