this.definitions

Types

Types.Text()

GeoPoint

GeoPoint.distanceBetween()

geoPoint.distanceTo()

Determine the spherical distance to the given point.

geoPoint.toString()

Simple serialization.

exports.GeoPoint

Export the GeoPoint class.

Model

ModelBaseClass(data)

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

ModelBaseClass mixes Validatable and Hookable classes methods

Arguments

Name

Type

Description

data

Object

initial object data

ModelBaseClass.defineProperty(prop, params)

Arguments

Name

Type

Description

prop

String

property name

params

Object

various property configuration

ModelBaseClass.toString()

Return string representation of class

modelBaseClass.toObject(onlySchema)

Convert model instance to a plain JSON object

Arguments

Name

Type

Description

onlySchema

Boolean

restrict properties to dataSource only, default to false. When onlySchema is true, only properties defined in
the schema are returned, otherwise all enumerable properties returned

Returns

Name

Type

Description

result

Object

canonical object representation (no getters and setters)

modelBaseClass.propertyChanged(propertyName)

Checks is property changed based on current property and initial value

Arguments

Name

Type

Description

propertyName

String

property name

modelBaseClass.reset()

Reset dirty attributes

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

module.exports

Module exports class Model

DataSource

DataSource(name, settings)

DataSource - connector-specific classes factory.

All classes in single dataSource shares same connector type and
one database connection

Arguments

Name

Type

Description

name

String

type of dataSource connector (mysql, mongoose, oracle, redis)

settings

Object

any database-specific settings which we need to establish connection (of course it depends on specific connector)

dataSource.discoverModelPropertiesSync(modelName, options)

dataSource.discoverPrimaryKeys(modelName, options, [cb])

Discover primary keys for a given owner/modelName

Each primary key column description has the following columns:

owner {String} => table schema (may be null)
tableName {String} => table name
columnName {String} => column name
keySeq {Number} => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
pkName {String} => primary key name (may be null)
The owner, default to current user

dataSource.discoverForeignKeysSync(modelName, options)

dataSource.discoverExportedForeignKeys(modelName, options, [cb])

Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table).
They are ordered by fkTableOwner, fkTableName, and keySeq.

dataSource.discoverSchema(modelName, [options], [cb])

Discover one schema from the given model without following the relations

Arguments

Name

Type

Description

modelName

String

The model name

[options]

Object

The options

[cb]

Function

The callback function

dataSource.discoverSchemas(modelName, [options], [cb])

Discover schema from a given modelName/view

options

{String} owner/schema - The database owner/schema name
{Boolean} relations - If relations (primary key/foreign key) are navigated
{Boolean} all - Ifall owners are included
{Boolean} views - If views are included

Arguments

Name

Type

Description

modelName

String

The model name

[options]

Object

The options

[cb]

Function

The callback function

dataSource.discoverSchemasSync(modelName, [options])

Discover schema from a given table/view synchronously

options

{String} owner/schema - The database owner/schema name
{Boolean} relations - If relations (primary key/foreign key) are navigated
{Boolean} all - Ifall owners are included
{Boolean} views - If views are included

Arguments

Name

Type

Description

modelName

String

The model name

[options]

Object

The options

dataSource.discoverAndBuildModels(modelName, [options], [cb])

Discover and build models from the given owner/modelName

options

{String} owner/schema - The database owner/schema name
{Boolean} relations - If relations (primary key/foreign key) are navigated
{Boolean} all - Ifall owners are included
{Boolean} views - If views are included

Arguments

Name

Type

Description

modelName

String

The model name

[options]

Object

The options

[cb]

Function

The callback function

dataSource.discoverAndBuildModelsSync(modelName, [options])

Discover and build models from the given owner/modelName synchronously

options

{String} owner/schema - The database owner/schema name
{Boolean} relations - If relations (primary key/foreign key) are navigated
{Boolean} all - Ifall owners are included
{Boolean} views - If views are included

Arguments

Name

Type

Description

modelName

String

The model name

[options]

Object

The options

dataSource.isActual([models])

Check whether migrations needed
This method make sense only for sql connectors.

Arguments

Name

Type

Description

[models]

Array.<String>

A model name or an array of model names. If not present, apply to all models

dataSource.freeze()

Freeze dataSource. Behavior depends on connector

dataSource.tableName(modelName)

Return table name for specified modelName

Arguments

Name

Type

Description

modelName

String

The model name

dataSource.columnName(modelName, propertyName)

Return column name for specified modelName and propertyName

Arguments

Name

Type

Description

modelName

String

The model name

propertyName

The property name

Returns

Name

Type

Description

result

String

columnName

dataSource.columnMetadata(modelName, propertyName)

Return column metadata for specified modelName and propertyName

Arguments

Name

Type

Description

modelName

String

The model name

propertyName

The property name

Returns

Name

Type

Description

result

Object

column metadata

dataSource.columnNames(modelName)

Return column names for specified modelName

Arguments

Name

Type

Description

modelName

String

The model name

Returns

Name

Type

Description

result

Array.<String>

column names

dataSource.idColumnName(modelName)

Find the ID column name

Arguments

Name

Type

Description

modelName

String

The model name

Returns

Name

Type

Description

result

String

columnName for ID

dataSource.idName(modelName)

Find the ID property name

Arguments

Name

Type

Description

modelName

String

The model name

Returns

Name

Type

Description

result

String

property name for ID

dataSource.idNames(modelName)

Find the ID property names sorted by the index

Arguments

Name

Type

Description

modelName

String

The model name

Returns

Name

Type

Description

result

Array.<String>

property names for IDs

dataSource.defineForeignKey(className, key, foreignClassName)

Define foreign key to another model

Arguments

Name

Type

Description

className

String

The model name that owns the key

key

String

name of key field

foreignClassName

String

The foreign model name

dataSource.disconnect([cb])

Close database connection

Arguments

Name

Type

Description

[cb]

Fucntion

The callback function

dataSource.enableRemote(operation)

Enable a data source operation to be remote.

Arguments

Name

Type

Description

operation

String

The operation name

dataSource.disableRemote(operation)

Disable a data source operation to be remote.

Arguments

Name

Type

Description

operation

String

The operation name

dataSource.getOperation(operation)

Get an operation's metadata.

Arguments

Name

Type

Description

operation

String

The operation name

dataSource.operations()

Get all operations.

dataSource.defineOperation(name, options, [Function} fn The function)

Define an operation to the data source

Arguments

Name

Type

Description

name

String

The operation name

options

Object

The options

[Function} fn The function

dataSource.isRelational()

Check if the backend is a relational DB

Returns

Name

Type

Description

result

Boolean

dataSource.ready(obj, args)

Check if the data source is ready

Arguments

Name

Type

Description

obj

args

Returns

Name

Type

Description

result

boolean

hiddenProperty(obj, key, value)

Define a hidden property

Arguments

Name

Type

Description

obj

Object

The property owner

key

String

The property name

value

Mixed

The default value

defineReadonlyProp(obj, key, value)

Define readonly property on object

Arguments

Name

Type

Description

obj

Object

The property owner

key

String

The property name

value

Mixed

The default value

exports.DataSource

Export public API

Data access mixins

DataAccessObject(data)

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

DataAccessObject mixes Inclusion classes methods

Arguments

Name

Type

Description

data

Object

initial object data

DataAccessObject.create(data, callback(err,)

Create new instance of Model class, saved in database

Arguments

Name

Type

Description

data

[optional]

callback(err,

obj) callback called with arguments:

err (null or Error)

instance (null or Model)

DataAccessObject.upsert(data, [callback])

Update or insert a model instance

Arguments

Name

Type

Description

data

Object

The model instance data

[callback]

Function

The callback function

DataAccessObject.findOrCreate(query, data, cb)

Find one record, same as all, limited by 1 and return object, not collection,
if not found, create using data provided as second argument

Arguments

Name

Type

Description

query

Object

search conditions: {where: {test: 'me'}}.

data

Object

object to create.

cb

Function

callback called with (err, instance)

DataAccessObject.exists(id, cb)

Check whether a model instance exists in database

Arguments

Name

Type

Description

id

id

identifier of object (primary key value)

cb

Function

callbacl called with (err, exists: Bool)

DataAccessObject.findById(id, cb)

Find object by id

Arguments

Name

Type

Description

id

primary key value

cb

Function

callback called with (err, instance)

DataAccessObject.find(params, callback)

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

Relation.belongsTo(anotherClass, params)

configuration {as: 'propertyName', foreignKey: 'keyName'}
Usage examples
Suppose model Post have a belongsTo relationship with User (the author of the post). You could declare it this way:
Post.belongsTo(User, {as: 'author', foreignKey: 'userId'});

When a post is loaded, you can load the related author with:
post.author(function(err, user) {
// the user variable is your user object
});

The related object is cached, so if later you try to get again the author, no additional request will be made.
But there is an optional boolean parameter in first position that set whether or not you want to reload the cache:
post.author(true, function(err, user) {
// The user is reloaded, even if it was already cached.
});

This optional parameter default value is false, so the related object will be loaded from cache if available.

exports.ValidationError

exports.Validatable

Basically validation configurators is just class methods, which adds validations
configs to AbstractClass._validations. Each of this validations run when
obj.isValid() method called.

Each configurator can accept n params (n-1 field names and one config). Config
is {Object} depends on specific validation, but all of them has one common part:
message member. It can be just string, when only one situation possible,
e.g. Post.validatesPresenceOf('title', { message: 'can not be blank' });