The :insert-ignore transact form allow you to insert rows, but on
:unique key conflict, discard the new row and keep the old.
(def db (rel/materialize {} [[:from :Customer] [:unique :id]]))
;; if there is no conflict, its just insert
(def db (rel/transact db [:insert-ignore :Customer {:id 42, :name "bob", :age 33}}]))
;; =>
{:Customer #{{:id 42, :name "bob", :age 33}}}
;; with a conflict, the new row will be discarded.
(rel/transact db [:insert-ignore :Customer {:id 42, :name "alice"}])
;; =>
{:Customer #{{:id 42, :name "bob", :age 33}}}
See also :insert-or-merge,
:insert-or-replace,
:insert-or-update,
:update.
Can you improve this documentation?Edit on GitHub
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 |