Hooks

See Hook API for available hook types

Defining hooks as part of Model definition

    const User = couchbase.define('User', {
        type: 'object'
    }, {
        hooks: {
            beforeCreate: function(user) {
                //do something
            }
        }
    })

Or on Model object

    User.beforeCreate(function(user) {
        //do something
    });

Register global hook

As option

    const couchbase = new couchbaseODM({
        bucket: bucket,
        hooks: {
            beforeCreate: function(instance) {
                //do something
            }
        }
    });

On CouchbaseODM instance

    couchbase.beforeCreate(function(instance) {
        //do something
    }, 'optional-hook-name');

Remove global hook

    //it's possible to delete named hooks only
    couchbase.removeHook('beforeCreate','hook-name');
comments powered by Disqus