if json, text, raw or urlencoded is used, the body of the request will be parse accordingly also the body of the response will be serialized accordingly.
var ModelEntity = model(options, attributes, plugins)
parameter
type
description
options
string | object
either model name for lazy loading or object for model configuration.
options.name
string
model name.
options.features
object
object contains special functionalities of the model. It is passed to data access layer.
options.query
array
array of QueryExpression repressing the query to be executed by default.
attributes
object
object describes the model schema. it contains key-value pairs where the key is a model attribute/field name and the value is the data type of this attribute/field. Data types are native javascript data types String, Number and Date. Data type could be javascript array of single object annotation [{}] or just an object annotation {} containing other key-value pairs expressing nested model schema.
plugins
array
array of mongoose plugins to define additional functionalities to the model.
return
type
description
ModelEntity
function
model constructor function prototyped as ModelEntity.
object contains key-value pairs where the key is a unique id for an operator and the value is a corresponding database engine operator. It is passed to data access layer.
var expression = new QueryExpression(options)
parameter
type
description
options
object
object describes a condition in a where clause of a query.
options.fieldName
string
attribute/field name of the model to be part of the condition.
options.comparisonOperator
string
a value represents comparison operation to be manipulated by database engine.
options.fieldValue
any
the value to be compared to the attribute/field of the model.
options.logicalOperator
string
a value represents logical operation to be manipulated by database to combine multiple conditions.
options.contextualLevel
number
starts with 0 represents the depth of the logical operation in the conditions tree. It is used to indicate brackets.
return
type
description
expression
object
object represents a condition expression combined with other expressions to represent a query. It is adapted by data access layer..
api configuration (name, version, path, method, parameters, returns)
constructor
function
logic function works by registering on methods to do functions regardless its orders, like (database processor query, insert, delete or update), data mapping to map returns of data to specific format or server error handling
data access
you should define your own data access layer like following
varbackend=require('backend-js');varModelController=function(){self.removeObjects=function(queryExprs,entity,callback){// do remove};self.addObjects=function(objsAttributes,entity,callback){// do add new};self.getObjects=function(queryExprs,entity,callback){// do select};self.save=function(callback,oldSession){// do select};};ModelController.defineEntity=function(name,attributes){// define entityreturnentity;};ModelController.prototype.constructor=ModelController;backend.setModelController(newModelController());
Starter project
A sample project that you can learn from examples how to use Backend-JS.