Members
connections :Array.<Object>
- Array.<Object>
drivers :Array.<Object>
- Array.<Object>
features :Array.<Object>
- Array.<Object>
schemas :Array.<Object>
- Array.<Object>
(static, constant) aggregateTypes :Array.<string>
- Array.<string>
- Default Value
- ['count', 'avg', 'min', 'max', 'sum']
(static, constant) alias :string
- string
- Default Value
- 'db'
(static, constant) propType :TPropType
Methods
(async) init()
Initialize plugin and performing the following tasks:
(async) modelCreate(name, optionsopt)
Create a new model:
- read corresponding schema
- attempt to create table/database/collection accordingly
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
options | Object | <optional> | {} | Options object |
- Source
(async) modelDrop(name, optionsopt)
Drop database model
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
options | Object | <optional> | {} | Options object |
- Source
(async) modelExists(name, thrownopt, optionsopt) → {boolean}
Check if model exists already
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
thrown | boolean | <optional> | false | If |
options | Object | <optional> | {} | Options object |
- Source
- Type:
- boolean
(async) pickRecord(optionsopt) → {Object}
Pick only fields defined from a record
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | {} | Options object Properties
|
- Type:
- Object
(async) prepPagination(filteropt, schema, options) → {TRecordPagination}
Prepare records pagination:
- making sure records limit is obeyed
- making sure page is a positive value
- if skip is given, recalculate limit to use skip instead of page number
- Build sort info
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
filter | Object | <optional> | {} | Filter object |
schema | Object | Model's schema | ||
options | Object | Options |
- Type:
- TRecordPagination
(async) recordCount(name, filteropt, optionsopt) → {TRecordCountResult|number}
Return the number of records found by given filter
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
filter | TRecordFilter | <optional> | {} | Filter object |
options | TRecordCountOptions | <optional> | {} |
- Source
Return number
of records if options.dataOnly
is set. TRecordCountResult otherwise
- Type:
- TRecordCountResult |
number
(async) recordCreate(name, body, optionsopt) → {TRecordCreateResult|Object}
Create a new record
Example:
const { recordCreate } = this.app.dobo
const { body } = {
id: 'ID',
name: 'Indonesia',
iso3: 'IDN'
}
const result = await recordCreate('CdbCountry', body)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
body | Object | Data to be saved | ||
options | TRecordCreateOptions | <optional> | {} |
- Source
Returns newly created record if options.dataOnly
is set. TRecordCreateResult otherwise
- Type:
- TRecordCreateResult |
Object
(async) recordFind(name, filteropt, optionsopt) → {TRecordFindResult|Array.<Object>}
Find records by model's name and given filter
Example: find records from model CdbCountry where its id is 'ID' or 'MY', sorted by name
in ascending order and return only its id
, name
and iso3
const { recordFind } = this.app.dobo
const query = { id: { $in: ['ID', 'MY'] } }
const sort = { name: 1 }
const fields = ['id', 'name', 'iso3']
const result = await recordFind('CdbCountry', { query, sort }, { fields })
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
filter | Object | <optional> | {} | Filter object |
options | TRecordFindOptions | <optional> | {} |
- Source
Return array
of records if options.dataOnly
is set. TRecordFindResult otherwise
- Type:
- TRecordFindResult |
Array.<Object>
(async) recordFindAll(name, filteropt, optionsopt) → {TRecordFindResult|Array.<Object>}
Find all records by model's name and given filter.
The total number of records returned is limited by hardLimit
value set in config file.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
filter | Object | <optional> | {} | Filter object |
options | TRecordFindOptions | <optional> | {} |
- Source
Return array
of records if options.dataOnly
is set. TRecordFindResult otherwise
- Type:
- TRecordFindResult |
Array.<Object>
(async) recordFindOne(name, filteropt, optionsopt) → {TRecordGetResult|Object}
Find the first record by model's name and given filter.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
filter | Object | <optional> | {} | Filter object |
options | TRecordFindOptions | <optional> | {} |
- Source
Return record's object
if options.dataOnly
is set. TRecordGetResult otherwise
- Type:
- TRecordGetResult |
Object
(async) recordGet(name, optionsopt) → {TRecordGetResult|Object}
Get record by model's name and record ID
Example:
const { recordGet } = this.app.dobo
const fields = ['id', 'name', 'iso3']
const result = await recordGet('CdbCountry', 'ID', { fields })
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
| string | | Record's ID | ||
options | TRecordGetOptions | <optional> | {} |
- Source
Return record's object
if options.dataOnly
is set. TRecordGetResult otherwise
- Type:
- TRecordGetResult |
Object
(async) recordRemove(name, id, optionsopt) → {TRecordRemoveResult|Object}
Remove existing record by it's ID. All attachments bound to this record will also be removed forever.
Example:
const { recordRemove } = this.app.dobo
const result = await recordRemove('CdbCountry', 'ID')
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
id | string | | Record's ID | ||
options | TRecordRemoveOptions | <optional> | {} |
- Source
Return the removed record if options.dataOnly
is set. TRecordRemoveResult otherwise
- Type:
- TRecordRemoveResult |
Object
(async) recordUpdate(name, id, body, optionsopt) → {TRecordUpdateResult|Object}
Update a record by it's ID and body payload
Example:
const { recordUpdate } = this.app.dobo
const { body } = {
name: 'Republic of Indonesia',
phoneCode: '+62'
}
const result = await recordUpdate('CdbCountry', 'ID', body)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
id | string | | Record's ID | ||
body | Object | Body payload | ||
options | TRecordUpdateOptions | <optional> | {} |
- Source
Returns updated record if options.dataOnly
is set. TRecordUpdateResult otherwise
- Type:
- TRecordUpdateResult |
Object
(async) recordUpsert(name, body, optionsopt) → {TRecordUpdateResult|TRecordCreateResult|Object}
Update a record by payload's ID. If no record is found by given ID, a new one will be created instead.
Missing ID in payload always results a new record creation.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | Model's name | ||
body | Object | Body payload | ||
options | TRecordUpsertOptions | <optional> | {} |
- Source
Returns updated/newly created record if options.dataOnly
is set. TRecordUpdateResult or TRecordCreateResult otherwise
- Type:
- TRecordUpdateResult |
TRecordCreateResult | Object
(async) start(connsopt, noRebuildopt)
Start plugin
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
conns | string | | <optional> | all | Which connections should be run on start |
noRebuild | boolean | <optional> | false | Set |
(async, static) sanitizeBody(optionsopt) → {Object}
Sanitize payload body against schema
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | {} | Properties
|
- Source
- Type:
- Object
(static) sanitizeDate(value, optionsopt) → {string|Date}
Sanitize value as a date/time value. Parse/format string using dayjs format
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | number | | Value to sanitize | ||||||||||||||||||||||
options | Object | <optional> | {} | Options object Properties
|
- Source
- Type:
- string |
Date
(static) sanitizeId(id, schema) → {number|string}
Sanitize id according it's schema
Name | Type | Description |
---|---|---|
id | number | | |
schema | Object |
- Source
- Type:
- number |
string
(async, static) validate(value, joiSchema, optionsopt) → {Object}
Validate value against JOI schema
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Object | value to validate | |||||||||||||||||||||||||||
joiSchema | Object | JOI schema | |||||||||||||||||||||||||||
options | Object | <optional> | {} | Options object Properties
|
- Source
- Type:
- Object