Guards make checks of payloads before the API call proper.
Guards make checks of payloads before the API call proper.
(bad-modifier doc)
A default guard for update!
, update-one!
, fetch-and-update-one!
.
The library exception for bad modifiers is a bit uninformative,
and has been replaced with a better one.
A default guard for `update!`, `update-one!`, `fetch-and-update-one!`. The library exception for bad modifiers is a bit uninformative, and has been replaced with a better one.
(bounce-empty doc)
A default guard for insert!
, insert-one!
.
An empty payload is allowed but does nothing.
A default guard for `insert!`, `insert-one!`. An empty payload is allowed but does nothing.
(empty-update doc)
A default guard for update!
, update-one!
, fetch-and-update-one!
, replace-one!
,
fetch-and-replace-one!
. An empty payload should always throw an exception.
A default guard for `update!`, `update-one!`, `fetch-and-update-one!`, `replace-one!`, `fetch-and-replace-one!`. An empty payload should always throw an exception.
(nil-update doc)
A default guard for update!
, update-one!
, fetch-and-update-one!
.
Ensure consistent exception for nil.
A default guard for `update!`, `update-one!`, `fetch-and-update-one!`. Ensure consistent exception for nil.
(return result)
Return early without making any API call.
Examples
Ignore any insert calls with a message:
(with-guards {:insert (fn [_] (return "a message"))}
(insert! :coll {:a 1})) ; No call made, just returns "a message"
Return early without making any API call. **Examples** Ignore any insert calls with a message: ```Clojure (with-guards {:insert (fn [_] (return "a message"))} (insert! :coll {:a 1})) ; No call made, just returns "a message" ```
(with-guards {:insert <insert-fn> :update <update-fn> :replace <replace-fn>}
&
<body>)
Guards for API functions. They allow you to check for payload conditions before a call is made. If the function returns truthy, the call goes through. If it returns falsy, no call is made, instead the payload is returned. For serious errors, throw an exception.
<insert-fn> guards insert!
. By default, it returns false for empty lists, true otherwise.
<update-fn> guards update!
, update-one!
, fetch-and-update-one!
. By default, it will
throw exceptions for a list payload and a root field that isn't a modifier. List
handling is a bit wonky. Since it's not needed, it's better to not accept it. The preset
exception for missing modifiers is unclear, and has been replaced.
Parameter | Description |
---|---|
:insert | optional fn Called for insert! . |
:update | optional fn Called for update! , update-one! , fetch-and-update-one! . |
:replace | optional fn Called for replace-one! , fetch-and-replace-one! . |
body | Encapsulated program calling the database. |
Examples
; Remove guards for payload:
(with-guards {:insert identity}
(insert! :coll [])) ; Throws exception
Guards for API functions. They allow you to check for payload conditions before a call is made. If the function returns truthy, the call goes through. If it returns falsy, no call is made, instead the payload is returned. For serious errors, throw an exception. <insert-fn> guards `insert!`. By default, it returns false for empty lists, true otherwise. <update-fn> guards `update!`, `update-one!`, `fetch-and-update-one!`. By default, it will throw exceptions for a list payload and a root field that isn't a modifier. List handling is a bit wonky. Since it's not needed, it's better to not accept it. The preset exception for missing modifiers is unclear, and has been replaced. | Parameter | Description | | --- | --- | | `:insert` | `optional fn` Called for `insert!`. | | `:update` | `optional fn` Called for `update!`, `update-one!`, `fetch-and-update-one!`. | | `:replace` | `optional fn` Called for `replace-one!`, `fetch-and-replace-one!`. | | `body` | Encapsulated program calling the database. | **Examples** ```Clojure ; Remove guards for payload: (with-guards {:insert identity} (insert! :coll [])) ; Throws exception ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close