Liking cljdoc? Tell your friends :D

Hooks, guards, and padding

There are three ways to automate interjection through call-back functions during calls:

  • document hooks,
  • preemptive guards,
  • payload padding.

Hooks

Hooks allow you to make operations on documents (queries and payloads) during an API call. The main intention is to allow schema conversions to and from MongoDB.

(require '[com.timezynk.mongo.hooks :refer [with-hooks]])

(with-hooks {:write #(rename-keys % {:a :b})
             :read  #(rename-keys % {:b :a})}
  (fetch-and-update-one! :coll
                         {:a 1}
                         {:$set {}}))

Guards

Guards allow you to add checks and operations before an API call is made. Inserts, updates, replacements each have their own guard.

Each guard has a default behaviour.

Insert

text

Update

text

Replace

text

Early Return

text

Padding

Can you improve this documentation? These fine people already did:
Lars & lars-timezynk
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close