Skip to content

Plugin Writing Guide

Ryan Schmukler edited this page Nov 13, 2013 · 5 revisions

Types of Plugins

Storage Layer / Sync Plugins

A sync plugin is a Modella plugin that implements Model.save, Model.update, and Model.remove static methods which are invoked by model#save and model#remove with this bound to the model instance. See the memory plugin for a bare bones implementation.

A sync plugin must add the following methods to the Model class and implement the required callback signatures:

Model.save(function(error, attributes))

Model.save is called with this bound to the model instance. It must store the instance's attributes and execute the callback with arguments error and attributes.

This method saves the instance for the first time, so must include the newly created id in attributes.

Model.update(function(error, attributes))

Model.update has the same signature as Model.save but the instance already has a primary id field, as it was previously saved.

Model.remove(function(error))

Model.remove is called with this bound to the model instance. It must remove the instance from storage and execute the callback with an optional error argument.