Members
adapter :string
Model's adapter name
- string
- Source
Methods
(async, static) _simpleLookup(value, lookupValue, optionsopt) → {*|null|undefined}
Internal method to perform a simple lookup based on the provided value and lookupValue.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
value | string | | The value to look up | ||
lookupValue | object | The lookup values to replace in the query | ||
options | object | <optional> | {} | Additional options for the lookup |
- Source
Returns the result of the lookup or null if not found or undefined if the value is not a string, object, or array
- Type:
- * |
null | undefined
(static) action(name, …args) → {DoboAction}
Invoke a model's action. It will create a new instance of DoboAction and return it.
| Name | Type | Attributes | Description |
|---|---|---|---|
name | string | The name of the action to invoke | |
args | any | <repeatable> | Arguments to pass to the action |
- Source
Returns an instance of DoboAction
- Type:
- DoboAction
(async, static) build(opts) → {DoboModel.TResultRecord|DoboModel.TRecord}
Build a model's definition based on its properties and rules.
| Name | Type | Description |
|---|---|---|
opts | DoboModel. | The options for building the model |
(async, static) buildFromDbModel(optionsopt) → {object|boolean}
Build JOI model from database model's properties and rules
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | <optional> | {} | Options object Properties
|
Returns JOI model object or false if no properties to validate
- Type:
- object |
boolean
(async, static) buildPropValues(prop, opts) → {Array.<DoboModel.TPropertyValue>}
Builds the values for a given property if prop.values is set:
- If a string, it will be treated as a handler and executed to get the values.
- If a function, it will be executed to get the values.
- If an array, it will be used as is.
Values are returned as an array of DoboModel.TPropertyValues. If a request object is provided in the options, the text will be translated using the request's translation function.
| Name | Type | Description |
|---|---|---|
prop | object | The property definition |
opts | DoboModel. | Additional options for building the property values |
- Source
Returns an array of property values
- Type:
- Array.<DoboModel.TPropertyValue>
(async, static) clearRecord(optsopt) → {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
Clears all records from the model's underlying data store.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
opts | DoboModel. | <optional> | {} | Options object. |
(async, static) countRecord(filteropt, optsopt) → {DoboAction|DoboModel.TResultRecord|DoboModel.TRecord}
Counts the number of records in the model's underlying data store that match the provided filter criteria.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filter | DoboModel. | <optional> | {} | The filter criteria to apply when counting records. |
opts | DoboModel. | <optional> | {} | Options object. |
(async, static) createRecord(body, optsopt) → {DoboAction|DoboModel.TResultCreateRecord|DoboModel.TRecord}
Creates a new record in the model's underlying data store with the provided data.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Description |
|---|---|---|---|
body | object | The data for the new record to be created | |
opts | DoboModel. | <optional> | Options object |
- See
- DoboModel.THookBeforeCreateRecord
- DoboModel.THookAfterCreateRecord
(async, static) drop(optsopt) → {DoboAction|DoboModel.TResult|boolean}
Drops the model from the underlying data store.
| Name | Type | Attributes | Description |
|---|---|---|---|
opts | DoboModel. | <optional> | Options object. |
- Source
- See
- DoboModel.THookBeforeDropModel
- DoboModel.THookAfterDropModel
- Type:
- DoboAction |
DoboModel. TResult |boolean
(async, static) findAllRecord(filter, optsopt) → {DoboAction|DoboModel.TResultFindRecord|Array.<DoboModel.TRecord>}
Finds all records from the model's underlying data store based on the provided filter.
| Name | Type | Attributes | Description |
|---|---|---|---|
filter | DoboModel. | The filter parameters for finding the records. | |
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeFindAllRecord
- DoboModel.THookAfterFindAllRecord
- Type:
- DoboAction |
DoboModel. TResultFindRecord |Array.<DoboModel.TRecord>
(async, static) findOneRecord(filter, optsopt) → {DoboAction|DoboModel.TResultFindRecord|Array.<DoboModel.TRecord>}
Finds a single record from the model's underlying data store based on the provided filter.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Description |
|---|---|---|---|
filter | DoboModel. | The filter parameters for finding the record. | |
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeFindRecord
- Type:
- DoboAction |
DoboModel. TResultFindRecord |Array.<DoboModel.TRecord>
(async, static) findRecord(filteropt, optsopt) → {DoboAction|DoboModel.TResultFindRecord|Array.<DoboModel.TRecord>}
Finds records in the model's underlying data store that match the provided filter criteria.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filter | DoboModel. | <optional> | {} | The filter criteria to apply when finding records. |
opts | DoboModel. | <optional> | {} | Options object. |
- See
- DoboModel.THookBeforeFindRecord
- DoboModel.THookAfterFindRecord
- Type:
- DoboAction |
DoboModel. TResultFindRecord |Array.<DoboModel.TRecord>
(static) getIndexes() → {Array.<object>}
Returns the model's indexes.
- Source
Returns an array of index objects defined in the model
- Type:
- Array.<object>
(static) getNonVirtualProperties(namesOnlyopt) → {Array.<(object|string)>}
Get the model's non-virtual properties.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
namesOnly | boolean | <optional> | false | If |
- Source
Returns an array of non-virtual properties or property names based on the namesOnly option
- Type:
- Array.<(object|string)>
(static) getProperties(optionsopt) → {Array.<(object|string)>}
Get the model's properties based on the given options.
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | {} | Options object Properties
|
- Source
Returns an array of properties or property names based on the options
- Type:
- Array.<(object|string)>
(static) getProperty(name) → {Object|null}
Get a property by its name.
| Name | Type | Description |
|---|---|---|
name | string | The name of the property to retrieve |
- Source
Returns the property object if found, otherwise undefined
- Type:
- Object |
null
(async, static) getRecord(id, optsopt) → {DoboAction|DoboModel.TResultGetRecord|DoboModel.TRecord}
Gets a record from the model's underlying data store based on the provided ID.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Description |
|---|---|---|---|
id | string | | The ID of the record to be retrieved. | |
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeGetRecord
- DoboModel.THookAfterGetRecord
(static) getVirtualProperties(namesOnlyopt) → {Array.<(object|string)>}
Get the model's virtual properties.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
namesOnly | boolean | <optional> | false | If |
- Source
Returns an array of virtual properties or property names based on the namesOnly option
- Type:
- Array.<(object|string)>
(static) hasProperty(name) → {boolean}
Checks if the model has a property with the given name.
| Name | Type | Description |
|---|---|---|
name | string | The name of the property to check |
- Source
Returns true if the property exists, otherwise false
- Type:
- boolean
(async, static) isExists(optsopt) → {DoboAction|DoboModel.TResult|boolean}
Checks if the model exists in the underlying data store.
| Name | Type | Attributes | Description |
|---|---|---|---|
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeModelExists
- DoboModel.THookAfterModelExists
- Type:
- DoboAction |
DoboModel. TResult |boolean
(async, static) removeRecord(id, optsopt) → {DoboAction|DoboModel.TResultRemoveRecord|DoboModel.TRecord}
Removes a record from the model's underlying data store based on the provided ID.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
id | string | | The ID of the record to be removed. | ||
opts | DoboModel. | <optional> | {} | Options object. |
- See
- DoboModel.THookBeforeRemoveRecord
- DoboModel.THookAfterRemoveRecord
(async, static) sanitizeBody(optionsopt) → {Object}
Sanitize the payload body based on the model's properties and rules.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | {} | Options object Properties
|
Returns sanitized body object
- Type:
- Object
(async, static) sanitizeFixture(paramsopt, optsopt) → {Object}
Sanitize a fixture object by resolving lookup values and ensuring proper data types.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | <optional> | {} | Parameters object Properties
| ||||||||||||||||||||
opts | DoboModel. | <optional> | {} | Options object for additional configurations |
Returns sanitized body object
- Type:
- Object
(static) sanitizeId(id) → {string|number}
Sanitize the given ID based on the model's properties.
| Name | Type | Description |
|---|---|---|
id | string | | The ID to sanitize |
- Source
Returns the sanitized ID
- Type:
- string |
number
(async, static) sanitizeRecord(recordopt, optsopt) → {Object}
Sanitize a record object based on the model's properties and rules.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
record | Object | <optional> | Record object | |||||||||||||||||||||||||||||||
opts | DoboModel. | <optional> | {} | Options object Properties
|
Returns sanitized record object
- Type:
- Object
(async, static) sanitizeRef(obj, fatalopt)
Sanitize a reference object based on the model's properties and rules.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj | * | The reference object to sanitize | ||
fatal | boolean | <optional> | true | Whether to throw an error if sanitization fails |
- Source
(async, static) updateRecord(id, body, optsopt) → {DoboAction|DoboModel.TResultUpdateRecord|DoboModel.TRecord}
Updates an existing record in the model's underlying data store based on the provided ID and data.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Description |
|---|---|---|---|
id | string | | The ID of the record to be updated. | |
body | object | The data to update the record with. | |
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeUpdateRecord
- DoboModel.THookAfterUpdateRecord
(async, static) upsertRecord(body, optsopt) → {DoboAction|DoboModel.TResultCreateRecord|DoboModel.TResultUpdateRecord|DoboModel.TRecord}
Upserts a record in the model's underlying data store. If a record with the specified ID exists, it updates that record; otherwise, it creates a new record.
If no arguments are provided, it automatically turns into a chainable DoboAction object.
| Name | Type | Attributes | Description |
|---|---|---|---|
body | object | The data for the record to be upserted. | |
opts | DoboModel. | <optional> | Options object. |
- See
- DoboModel.THookBeforeUpsertRecord
- DoboModel.THookAfterUpsertRecord
(async, static) validate(body, joiModel, optionsopt) → {Object}
Validate body object against JOI model
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
body | Object | Body object to validate | ||||||||||||||||||||||
joiModel | Object | JOI model | ||||||||||||||||||||||
options | Object | <optional> | {} | Options object Properties
|
- Type:
- Object
Type Definitions
TFilter
- Object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
query | string | | <optional> | {} | Query definition. See query-language for more |
limit | number | Maximum number of records to return | ||
page | number | Which page to return | ||
skip | number | Records to skip | ||
sort | DoboModel. | Sort order info |
- See
- Dobo#recordFind
- Dobo#recordFindOne
- Dobo#recordFindAll
TOptions
- Object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
noHook | boolean | <optional> | false | If |
noModelHook | boolean | <optional> | false | If |
noDynHook | boolean | <optional> | false | If |
noValidation | boolean | <optional> | false | If |
noCheckUnique | boolean | <optional> | false | If |
noBodySanitizer | boolean | <optional> | false | If |
noRecordSanitizer | boolean | <optional> | false | If |
noResult | boolean | <optional> | false | If |
truncateString | boolean | <optional> | true | If |
partial | boolean | <optional> | If | |
dataOnly | boolean | <optional> | true | If |
- Source
TPagination
- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
limit | number | Number of records per page | |
page | number | Page number | |
skip | number | <optional> | Records to skip. If not provided, it will be calculated based on |
- Source
TPropertyType
- Object
| Name | Type | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
integer | Object | Properties
| |||||||||||||||||||||
smallint | Object | Properties
| |||||||||||||||||||||
text | Object | Properties
| |||||||||||||||||||||
string | Object | Properties
| |||||||||||||||||||||
float | Object | Properties
| |||||||||||||||||||||
double | Object | Properties
| |||||||||||||||||||||
boolean | Object | Properties
| |||||||||||||||||||||
datetime | Object | Properties
| |||||||||||||||||||||
date | Object | Properties
| |||||||||||||||||||||
time | Object | Properties
| |||||||||||||||||||||
timestamp | Object | Properties
| |||||||||||||||||||||
object | Object | {} | |||||||||||||||||||||
array | Object | {} |
TPropertyValue
Property value type definition. Used for building property values in a model which is an array of this object type.
- Object
| Name | Type | Description |
|---|---|---|
value | string | The actual value of the property |
text | string | The display text for the property value, which can be translated based on the request context |
- Source
TRecord
The record returned from a model's action. It is an object where:
- Key represents the property name
- Value represents its value according to the property's data type
This record is then merged with DoboModel.TRecordFormatted and DoboModel.TRecordRef to form the final record returned from a model's action.
- Object |
DoboModel. TRecordFormatted |DoboModel. TRecordRef
- Source
{
id: 1,
item: "Laptop",
createdAt: "2024-01-01T00:00:00.000Z",
isActive: true,
price: 2500.00,
_fmt: {
id: "1",
item: "Laptop",
createdAt: "Jan 1, 2024, 12:00 AM",
isActive: "True",
price: "2,500.00"
},
_ref: {
user: {
id: 1,
name: "John Doe"
}
}
}TRecordFormatted
Formatted version of a record's property values. It is an object where:
- Key represents the property name
- Value represents its formatted value according to the property's data type or formatting function. Data type is ALWAYS in string.
This record is then wrapped in a _fmt property.
- Object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
_fmt | Object | <optional> | {} | Wrapper |
- Source
{
_fmt: {
id: "1",
item: "Laptop",
createdAt: "Jan 1, 2024, 12:00 AM",
isActive: "True",
price: "2,500.00"
}
}TRecordRef
Reference record related to a record's result. It is an object where:
- Key represents the name of the referenced record. Normally, it is the referenced model's name in camelCase format.
- Value represents its reference record. It can be an object or an array of objects, depending on the relationship type.
This record is then wrapped in a _ref property in the result object.
- Object
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
_ref | Object | <optional> | {} | Wrapper Properties
|
- Source
{
_ref: {
user: {
id: 1,
name: "John Doe"
},
posts: [
{
id: 1,
title: "Post Title"
},
{
id: 2,
title: "Another Post Title"
}
]
}
}TResultCreateRecord
The result returned from a model's createRecord action if dataOnly is set to false.
- Object
| Name | Type | Description |
|---|---|---|
data | DoboModel. | The data returned from the action |
- Source
TResultFindRecord
The result returned from a model's find* actions if dataOnly is set to false.
- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
data | Array.<DoboModel.TRecord> | The data returned from the action | |
count | number | <optional> | The total number of records found, if applicable |
cached | boolean | <optional> | Indicates if the result was retrieved from cache, if applicable. Only available if |
warnings | Array | <optional> | Any warnings generated during the action, if applicable |
- Source
TResultGetRecord
The result returned from a model's getRecord action if dataOnly is set to false.
- Object
| Name | Type | Description |
|---|---|---|
data | DoboModel. | The data returned from the action |
- Source
TResultRecord
The result returned from a model's action other than find*, {create|update|remove}Record if dataOnly is set to false.
- Object
| Name | Type | Description |
|---|---|---|
data | Array.<DoboModel.TRecord> | The data returned from the action |
- Source
TResultRemoveRecord
The result returned from a model's removeRecord action if dataOnly is set to false.
- Object
| Name | Type | Description |
|---|---|---|
oldData | DoboModel. | The removed data returned from the action |
- Source
TResultUpdateRecord
The result returned from a model's updateRecord action if dataOnly is set to false.
- Object
| Name | Type | Description |
|---|---|---|
data | DoboModel. | The updated data returned from the action |
oldData | DoboModel. | The previous data before the update |
- Source
TSort
Key value pairs used as sort order in pagination and sorting of records. It is an object where:
- Key represents model's field name
- Value represents its sort order
- Object.<string, DoboModel.TSortOrder>
- Source
// to sort by firstName (ascending) and lastName (descending)
const sort = {
firstName: 1,
lastName: -1
}TSortOrder
Sort order key used in pagination and sorting of records. It can be either:
1for ascending order (the default, if none is provided) or-1for descending order.
- string
- Source
TValidator
All available validators to check against model's properties and rules
- Object
| Name | Type | Description |
|---|---|---|
string | TValidatorString | |
number | TValidatorNumber | |
boolean | TValidatorBoolean | |
date | TValidatorDate | |
timestamp | TValidatorTimestamp | |
array | TValidatorArray |
TValidatorArray
List of available array validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | length | |
1 | string | max | |
2 | string | min |
TValidatorBoolean
List of available boolean validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | falsy | |
1 | string | sensitive | |
2 | string | truthy |
TValidatorDate
List of available date validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | greater | |
1 | string | iso | |
2 | string | less | |
3 | string | max | |
4 | string | min |
TValidatorNumber
List of available number validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | great | |
1 | string | less | |
2 | string | max | |
3 | string | min | |
4 | string | multiple | |
5 | string | negative | |
6 | string | port | |
7 | string | positive | |
8 | string | sign | |
9 | string | unsafe |
TValidatorString
List of available string validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | alphanum | |
1 | string | base64 | |
2 | string | case | |
3 | string | creditCard | |
4 | string | dataUri | |
5 | string | ||
6 | string | guid | |
7 | string | uuid | |
8 | string | hex | |
9 | string | hostname | |
10 | string | insenstive | |
11 | string | ip | |
12 | string | isoDate | |
13 | string | isoDuration | |
14 | string | length | |
15 | string | lowercase | |
16 | string | max | |
17 | string | min | |
18 | string | normalize | |
19 | string | pattern | |
20 | string | regex | |
21 | string | replace | |
22 | string | token | |
23 | string | trim | |
24 | string | truncate | |
25 | string | upercase | |
26 | string | uri |
TValidatorTimestamp
List of available timestamp validators to check against model's properties and rules
- Array.<string>
| Name | Type | Default | Description |
|---|---|---|---|
0 | string | timestamp |