Abstract class - base class for all persist objects provides common API to access any database adapter. This class describes only abstract behavior layer, refer to lib/adapters/*.js to learn more about specific adapter implementations

AbstractClass mixes Validatable and Hookable classes methods

param Object data - initial object data

Source code
Class methods Instance methods Helper methods


Declared as function (prop, params)

param String prop - property name
param Object params - various property configuration

Source code


Declared as function (data, callback)

Create new instance of Model class, saved in database

param data [optional]
param callback(err, obj) callback called with arguments:

  • err (null or Error)
  • instance (null or Model)
Source code


Declared as AbstractClass.updateOrCreate

Update or insert

Source code


Declared as function exists(id, cb)

Check whether object exitst in database

param id id - identifier of object (primary key value)
param Function cb - callbacl called with (err, exists: Bool)

Source code


Declared as function find(id, cb)

Find object by id

param id id - primary key value
param Function cb - callback called with (err, instance)

Source code


Declared as function all(params, cb)

Find all instances of Model, matched by query make sure you have marked as index: true fields for filter or sort

param Object params (optional)

  • where: Object { key: val, key2: {gt: 'val2'}}
  • order: String
  • limit: Number
  • skip: Number

param Function callback (required) called with arguments:

  • err (null or Error)
  • Array of instances
Source code


Declared as function findOne(params, cb)

Find one record, same as all, limited by 1 and return object, not collection

param Object params - search conditions
param Function cb - callback called with (err, instance)

Source code


Declared as function destroyAll(cb)

Destroy all records
param Function cb - callback called with (err)

Source code


Declared as function (where, cb)

Return count of matched records

param Object where - search conditions (optional)
param Function cb - callback, called with (err, count)

Source code


Declared as function ()

Return string representation of class

override default toString method

Source code


Declared as function hasMany(anotherClass, params)

Declare hasMany relation

param Class anotherClass - class to has many
param Object params - configuration {as:, foreignKey:}
example User.hasMany(Post, {as: 'posts', foreignKey: 'authorId'});

Source code


Declared as function (anotherClass, params)

Declare belongsTo relation

param Class anotherClass - class to belong
param Object params - configuration {as: 'propertyName', foreignKey: 'keyName'}

Source code


Declared as function (name, params)

Define scope TODO: describe behavior and usage examples

Source code


Declared as function (options, callback)

Save instance. When instance haven't id, create method called instead. Triggers: validate, save, update | create
param options {validate: true, throws: false} [optional]
param callback(err, obj)

Source code


Declared as function ()

Return adapter of current record

Source code


Declared as function (onlySchema)

Convert instance to Object

param Boolean onlySchema - restrict properties to schema only, default false when onlySchema == true, only properties defined in schema returned, otherwise all enumerable properties returned
returns Object - canonical object representation (no getters and setters)

Source code


Declared as function (cb)

Delete object from persistence

triggers destroy hook (async) before and after destroying object

Source code


Declared as function updateAttribute(name, value, callback)

Update single attribute

equals to `updateAttributes({name: value}, cb)

param String name - name of property
param Mixed value - value of property
param Function callback - callback called with (err, instance)

Source code


Declared as function updateAttributes(data, cb)

Update set of attributes

this method performs validation before updating

trigger validation, save and update hooks
param Object data - data to update
param Function callback - callback called with (err, instance)

Source code


Declared as function propertyChanged(attr)

Checks is property changed based on current property and initial value

param String attr - property name
return Boolean

Source code


Declared as function reload(callback)

Reload object from persistence

requires id member of object to be able to call find
param Function callback - called with (err, instance) arguments

Source code


Declared as function ()

Reset dirty attributes

this method does not perform any database operation it just reset object to it's initial state

Source code


Declared as function isdef(s)

Check whether s is not undefined
param Mixed s
return Boolean s is undefined

Source code


Declared as function merge(base, update)

Merge base and update params
param Object base - base object (updating this object)
param Object update - object with new data to update base
returns Object base

Source code


Declared as function defineReadonlyProp(obj, key, value)

Define readonly property on object

param Object obj
param String key
param Mixed value

Source code


Declared as function addToCache(constr, obj)

Add object to cache

Source code


Declared as function touchCache(constr, id)

Renew object position in LRU cache index

Source code


Declared as function getCached(constr, id)

Retrieve cached object

Source code


Declared as function clearCache(constr)

Clear cache (fully)

removes both cache and LRU index

param Class constr - class constructor

Source code


Declared as function removeFromCache(constr, id)

Remove object from cache

param Class constr
param id id

Source code

© 1602 Software