Skip to content
eduardoejp edited this page May 24, 2012 · 4 revisions

(use 'clj-orient.core)

Hooks allow you to listen-in to operations being performed on the database both before and after they happen. You can create a hook using the defhook macro and you add it to the DB using add-hook, e.g.:

(defhook log-hook "Optional doc-string."
  (after-create [x] (println "Created:" x)))

(add-hook! log-hook)

The available operations for your hooks are before-create, before-read, before-update, before-delete, after-create, after-read, after-update andafter-delete. Each is passed the document already wrapped in a CljODoc object.

Note: In the before operations, you have to return true in order for the operation to be considered succesful. If you return false or nil, it will stop the operation from ocurring and throw an exception. The after operations are void, so return values don't matter.

Clone this wiki locally