API Reference

SchemaType Class

Defined in lib/schematype.js:1

Description

The basic schema type constructor.

This is an abstract class. Every schema type should inherit this class. For example:

var SchemaCustom = function(options){
SchemaType.call(this, options);
};
SchemaCustom.__proto__ = SchemaType;
SchemaCustom.prototype.__proto__ = SchemaType.prototype;

Query operators

To add a query operator, adds a method whose name started with q$. For example:

SchemaCustom.q$foo = function(data, value){
// ...
};

The data parameter is the data in the database; the value parameter is the value passed to the query operator.
The return value should be a boolean indicating whether the data passed the test.

Update operators

To add a update operator, adds a method whose name started with u$. For example:

SchemaCustom.u$bar = function(data, value){
// ...
};

The data parameter is the data in the database; the value parameter is the value passed to the update operator.
The return value will replace the original data.

Constructor

SchemaType

([options])
Defined in lib/schematype.js:1

The basic schema type constructor.

This is an abstract class. Every schema type should inherit this class. For example:

var SchemaCustom = function(options){
SchemaType.call(this, options);
};
SchemaCustom.__proto__ = SchemaType;
SchemaCustom.prototype.__proto__ = SchemaType.prototype;

Query operators

To add a query operator, adds a method whose name started with q$. For example:

SchemaCustom.q$foo = function(data, value){
// ...
};

The data parameter is the data in the database; the value parameter is the value passed to the query operator.
The return value should be a boolean indicating whether the data passed the test.

Update operators

To add a update operator, adds a method whose name started with u$. For example:

SchemaCustom.u$bar = function(data, value){
// ...
};

The data parameter is the data in the database; the value parameter is the value passed to the update operator.
The return value will replace the original data.

Parameters

Methods

cast

(value) Any

Casts a value.

Parameters

  • value Any

Returns

  • Any

checkRequired

(value) Any

Validates a value.

Parameters

  • value Any

Returns

  • Any

compare

(data, value) Boolean

Compares data.

Parameters

  • data Any
  • value Any

Returns

q$exists

(data, value) Boolean

Checks whether the field exists.

q$exists is also aliased as q$exist.

Parameters

  • data Any
  • value Any

Returns

q$gt

(data, value) Boolean

Checks whether data is greater than value.

Parameters

  • data Any
  • value Any

Returns

q$gte

(data, value) Boolean

Checks whether data is greater than or equal to value.

q$gte is also aliased as q$min.

Parameters

  • data Any
  • value Any

Returns

q$in

(data, value) Boolean

Checks whether data contains value.

Parameters

  • data Any
  • value Any

Returns

q$lt

(data, value) Boolean

Checks whether data is less than value.

Parameters

  • data Any
  • value Any

Returns

q$lte

(data, value) Boolean

Checks whether data is less than or equal to value.

q$lte is also aliased as q$max.

Parameters

  • data Any
  • value Any

Returns

q$ne

(data, value) Boolean

Checks whether data is equal to value. If not, return true.

Parameters

  • data Any
  • value Any

Returns

q$nin

(data, value) Boolean

Checks whether data not contains value.

Parameters

  • data Any
  • value Any

Returns

q$where

(data, value) Boolean

Validates data with value function.

Parameters

Returns

q$within

(data, value) Boolean

Checks whether data is between value.

Parameters

Returns

q$without

(data, value) Boolean

Checks whether data is not between value.

Parameters

Returns

save

(value) Any

Transforms a value into JSON.

Parameters

  • value Any

Returns

  • Any

Properties

default

The default value of the field.

required

Determines whether the field is required.