-
Notifications
You must be signed in to change notification settings - Fork 9
rcouch hooks
Benoit Chesneau edited this page Feb 7, 2015
·
5 revisions
rcouch version 1.2.x introduces a new hook mechanism in preview. Each module can subscribe to events and a hook in the module code is called when the event occurs.
Note: in the version 1.2.x the mechanism is dedicated to database hooks but more will be added soon.
couch_users_db.erl is an example how the hook mechanisme can be used.
Functions to register the hooks:
couch_hooks:add(Hook, DbName, Module, Function, Priority)
couch_hooks:delete(Hook, DbName, Module, Function, Priority)
-
Hook = atom()
: name of the event (see below). -
Host = string() | binary() |'*'
: name of the database or the atom'*'
for all. -
Module = atom()
: module to call. can beundefined
-
Function = atom()
: function to call -
Priority = integer()
: determine in which order the hooks are run (when several hooks are defined for the same event). Useful if you want to chain some hooks.
-
after_doc_read(Doc, Db) -> Doc2
: sent after a doc has been read from the filesystem -
before_doc_update(Doc, Db) -> Doc2
: sent before updating the document. Useful to modify the document before updating it to the filesystem.