Helper
model:find(name, opts)
Find records from DAB that matched your query.
See this for details.
Usage:
helper('model:find')(name, opts)
name
<string> Required.body
<Object> Required.opts
<Object> Default:{}
query
<object> DAB query. Default:{}
limit
<integer> Limit number of results. Defaults tocommon.default.limit
from your model.jsonpage
<integer> Page number. Default:1
sort
<Object> Default:{}
Object like this:
{
"success": true,
"total": 100,
"data": [{
"_id": "james-bond",
"first_name": "James",
"last_name": "Bond",
"age": 38
}, {
"_id": "jack-bauer",
"first_name": "Jack",
"last_name": "Bauer",
"age": null
}]
}
More info here
model:findOne(name, id)
Usage:
helper('model:findOne')(name, id, opts)
name
<string> Required.id
<string | integer> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
model:create
Usage:
helper('model:create')(name, body, opts)
name
<string> Required.body
<Object> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipValidation
<Object> Default:{}
skipHook
: <Object> Default:{}
beforeValidate
<boolean> Default:false
afterValidate
<boolean> Default:false
beforeCreate
<boolean> Default:false
afterCreate
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:update
Usage:
helper('model:update')(name, id, body, opts)
name
<string> Required.id
<string | integer> Required.body
<Object> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipValidation
<Object> Default:{}
skipHook
<Object> Default:{}
beforeValidate
<boolean> Default:false
afterValidate
<boolean> Default:false
beforeUpdate
<boolean> Default:false
afterUpdate
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:remove
Usage:
helper('model:remove')(name, id, opts)
name
<string> Required.id
<string | integer> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipValidation
<Object> Default:{}
skipHook
<Object> Default:{}
beforeValidate
<boolean> Default:false
afterValidate
<boolean> Default:false
beforeRemove
<boolean> Default:false
afterRemove
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:bulkCreate
Usage:
helper('model:bulkCreate')(name, body, opts)
name
<string> Required.body
<Object> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipHook
<Object> Default:{}
beforeBulkCreate
<boolean> Default:false
afterBulkCreate
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:bulkUpdate
Usage:
helper('model:bulkUpdate')(name, body, opts)
name
<string> Required.body
<Object> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipHook
<Object> Default:{}
beforeBulkUpdate
<boolean> Default:false
afterBulkUpdate
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:bulkRemove
Usage:
helper('model:bulkRemove')(name, body, opts)
name
<string> Required.body
<Object> Required.opts
<Object> Default:{}
dab
<object> DAB options. Default:{}
skipHook
<Object> Default:{}
beforeBulkRemove
<boolean> Default:false
afterBulkRemove
<boolean> Default:false
all
<boolean> Skip all hooks altogether. Default:false
model:copyFrom(name, src, opts)
Usage:
helper('model:copyFrom')(name, src, opts)
model:copyTo(name, dest, opts)
Usage:
helper('model:copyTo')(name, dest, opts)
model:validate(name, ...args)
model:get(name)
Object of the following convenient proxy helpers & instance or throws error if something isn't right:
dab
: convenient helper of getDabschema
: convenient proxy of getSchemahook
: convenient proxy of getHookfind
: convenient proxy of findfindOne
: convenient proxy of findOnecreate
: convenient proxy of createupdate
: convenient proxy of updateremove
: convenient proxy of removebulkCreate
: convenient proxy of bulkCreatebulkUpdate
: convenient proxy of bulkUpdatebulkRemove
: convenient proxy of bulkRemovecopyFrom
: convenient proxy of copyFromcopyTo
: convenient proxy of copyTo
...
const model = helper('model:get')('app:myModel')
model.create({ first_name: 'James', last_name: 'Blondy' })
.then(result => {
return model.update(result.data.id, { last_name: 'Bond' })
})
.then(result => {
return model.find()
})
.then(result => {
console.log(result)
/* result is object of something like this:
{
success: true,
total: 1,
data: [{
_id: '<auto_generated_id>',
first_name: 'James',
last_name: 'Bond'
}]
}
*/
})
.catch(err => {
console.log(err.message)
})
model:getConnector(name, follow)
model:getDab(name)
model:getHook(name, hook)
model:getSchema(name)
Last updated