Pad payload before sending to database.
Pad payload before sending to database.
(with-padding {:insert <insert-fn> :update <update-fn> :replace <replace-fn>}
&
<body>)Optional padding of each payload document, before sending to the database.
You may for example want to add a created field for timestamping each inserted
document.
| 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
; Add created field:
(with-pads {:insert (fn [doc] (assoc doc :created (System/currentTimeMillis)))}
(insert! :coll [])) ; Throws exception
Optional padding of each payload document, before sending to the database.
You may for example want to add a `created` field for timestamping each inserted
document.
| 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
; Add created field:
(with-pads {:insert (fn [doc] (assoc doc :created (System/currentTimeMillis)))}
(insert! :coll [])) ; Throws exception
```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 |