Extends
Members
idField :DoboAdapter.TIdField
ID field configuration
- Source
maxChunkSize :number
Maximum chunk size for bulk operations
- number
- Source
memory :boolean
Indicates whether the adapter uses in-memory storage
- boolean
- Source
name :string
Adapter name
- string
- Source
options :object
Adapter options
- object
- Source
support :DoboAdapter.TSupport
Support configuration for the adapter
- Source
useUtc :boolean
Indicates whether to use UTC for datetime fields
- boolean
- Source
Methods
(async) _attachHook(name, model, …args)
Attaches hooks to the model for various operations. It runs the appropriate hooks before and after the specified operation, allowing for custom behavior to be injected into the model's lifecycle.
| Name | Type | Attributes | Description |
|---|---|---|---|
name | string | The name of the hook | |
model | DoboModel | The model instance to which the hook is being attached | |
args | any | <repeatable> | Additional arguments to be passed to the hook |
- Source
(async) _buildModel(model, options) → {Promise.<object>}
Wrapper for the buildModel method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _bulkCreateRecord(model, bodies, options) → {Promise.<void>}
Wrapper for the DoboAdapter#bulkCreateRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
bodies | Array.<object> | |
options | object |
- Source
- Type:
- Promise.<void>
(async) _checkUnique(model, body, options) → {Promise.<void>}
Checks the uniqueness of fields with a unique index.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance to check |
body | object | The data to be checked for uniqueness |
options | object | Additional options, including the action being performed |
- Source
- Resolves if unique, throws an error if not
- Type:
- Promise.<void>
(async) _clearRecord(model, options) → {Promise.<object>}
Wrapper for the DoboAdapter#clearRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _countRecord(model, filter, options) → {Promise.<object>}
Wrapper for the DoboAdapter#countRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
filter | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _createAggregate(model, filter, params, options) → {Promise.<object>}
Wrapper for the DoboAdapter#createAggregate method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
filter | object | |
params | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _createHistogram(model, filter, params, options) → {Promise.<object>}
Wrapper for the DoboAdapter#createHistogram method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
filter | object | |
params | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _createRecord(model, input, options) → {Promise.<object>}
Wrapper for the DoboAdapter#createRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
input | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _dropModel(model, options) → {Promise.<object>}
Wrapper for the dropModel method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _findAllRecord(model, filter, options) → {Promise.<object>}
Finds all records for the given model based on the provided filter. This method will only run if child adapter does not implement DoboAdapter#findAllRecord.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the records are being found |
filter | object | The filter criteria for finding records |
options | object | Additional options that may affect record finding |
- Source
- The result of the record finding
- Type:
- Promise.<object>
(async) _findRecord(model, filter, options) → {Promise.<object>}
Wrapper for the DoboAdapter#findRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
filter | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _getRecord(model, id, options) → {Promise.<object>}
Wrapper for the DoboAdapter#getRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
id | string | | |
options | object |
- Source
- Type:
- Promise.<object>
_getReturningFields(model, options) → {Array.<string>}
Get returning fields for a model based on the provided options. If the adapter supports returning fields, it will return the specified fields or all model properties. It ensures that the ID field is always included in the returned fields.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which to get the returning fields |
options | object | Options that may include the fields to return |
- Source
- Array of field names to be returned
- Type:
- Array.<string>
(async) _modelExists(model, options) → {Promise.<boolean>}
Wrapper for the modelExists method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
options | object |
- Source
- Type:
- Promise.<boolean>
(async) _prepBodyForCreate(model, body, options) → {Promise.<object>}
Prepares the body of a record for creation by populating default values for properties that are not set. It handles various types of default values, including functions, special strings (like 'now', 'uuid', etc.), and static values.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the body is being prepared |
body | object | The data to be prepared for creation |
options | object | Additional options that may affect the preparation |
- Source
- The prepared body with default values populated
- Type:
- Promise.<object>
(async) _prepIdForCreate(model, body, options) → {Promise.<void>}
Prepares the ID for a record before creation. It generates an ID if it is not set in the body.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the ID is being prepared |
body | object | The data containing the ID |
options | object | Additional options that may affect ID generation |
- Source
- Resolves when the ID has been prepared
- Type:
- Promise.<void>
(async) _removeRecord(model, id, options) → {Promise.<object>}
Wrapper for the DoboAdapter#removeRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
id | string | | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _updateRecord(model, id, input, options) → {Promise.<object>}
Wrapper for the DoboAdapter#updateRecord method, called internally by model to make sure all adapter hooks are executed accordingly, and all inputs and outputs are sanitized.
| Name | Type | Description |
|---|---|---|
model | DoboModel | |
id | string | | |
input | object | |
options | object |
- Source
- Type:
- Promise.<object>
(async) _upsertRecord(model, input, options) → {Promise.<object>}
Upserts a record for the given model. This method will only run if child adapter does not implement DoboAdapter#upsertRecord.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being upserted |
input | object | The input data for the upsert |
options | object | Additional options that may affect record upserting |
- Source
- The result of the record upsert
- Type:
- Promise.<object>
(async) buildModel(model, options)
Builds the model in the database.
Must be implemented by child classes to provide specific database functionality for model building, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being built |
options | object | Additional options that may affect model building |
- Source
(async) bulkCreateRecord(model, bodies, options) → {Promise.<void>}
Bulk creates records for the given model.
Must be implemented by child classes to provide specific database functionality for bulk record creation, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the records are being created |
bodies | Array.<object> | The array of input data for the new records |
options | object | Additional options that may affect record creation |
- Source
- Resolves when the records have been created
- Type:
- Promise.<void>
(async) clearRecord(model, options) → {Promise.<object>}
Clears all records for the given model.
Must be implemented by child classes to provide specific database functionality for record clearing, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the records are being cleared |
options | object | Additional options that may affect record clearing |
- Source
- The result of the record clearing
- Type:
- Promise.<object>
(async) connect(connection, noRebuild) → {Promise.<void>}
Connects to the database using the provided connection parameters.
| Name | Type | Description |
|---|---|---|
connection | * | The connection parameters for the database |
noRebuild | * | Flag indicating whether to skip rebuilding the database schema |
- Source
- Resolves when the connection is established
- Type:
- Promise.<void>
(async) countRecord(model, filter, options) → {Promise.<object>}
Counts the records for the given model based on the provided filter.
Must be implemented by child classes to provide specific database functionality for record counting, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the records are being counted |
filter | object | The filter criteria for counting records |
options | object | Additional options that may affect record counting |
- Source
- The result of the record counting
- Type:
- Promise.<object>
(async) createAggregate(model, filter, params, options) → {Promise.<object>}
Creates an aggregate for the given model based on the provided filter and parameters.
Must be implemented by child classes to provide specific database functionality for aggregate creation, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the aggregate is being created |
filter | object | The filter criteria for creating the aggregate |
params | object | The parameters for the aggregate creation |
options | object | Additional options that may affect aggregate creation |
- Source
- The result of the aggregate creation
- Type:
- Promise.<object>
(async) createHistogram(model, filter, params, options) → {Promise.<object>}
Creates a histogram for the given model based on the provided filter and parameters.
Must be implemented by child classes to provide specific database functionality for histogram creation, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the histogram is being created |
filter | object | The filter criteria for creating the histogram |
params | object | The parameters for the histogram creation |
options | object | Additional options that may affect histogram creation |
- Source
- The result of the histogram creation
- Type:
- Promise.<object>
(async) createRecord(model, input, options) → {Promise.<object>}
Creates a new record for the given model.
Must be implemented by child classes to provide specific database functionality for record creation, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being created |
input | object | The input data for the new record |
options | object | Additional options that may affect record creation |
- Source
- The result of the record creation
- Type:
- Promise.<object>
(async) dispose() → {Promise.<void>}
Disposes of the adapter, performing any necessary cleanup operations.
- Source
- Resolves when the adapter has been disposed
- Type:
- Promise.<void>
(async) dropModel(model, options)
Drops the model from the database.
Must be implemented by child classes to provide specific database functionality for dropping a model, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being dropped |
options | object | Additional options that may affect record dropping |
- Source
(async) findRecord(model, filter, options) → {Promise.<object>}
Finds records for the given model based on the provided filter.
Must be implemented by child classes to provide specific database functionality for record finding, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the records are being found |
filter | object | The filter criteria for finding records |
options | object | Additional options that may affect record finding |
- Source
- The result of the record finding
- Type:
- Promise.<object>
getRealFields(model) → {Array.<string>}
Utility method to get the real fields of a model, excluding virtual fields. This is useful for operations that require only the actual stored properties of a model.
| Name | Type | Description |
|---|---|---|
model | * |
- Source
- Array of real field names
- Type:
- Array.<string>
(async) getRecord(model, id, options) → {Promise.<object>}
Retrieves a record for the given model by its ID.
Must be implemented by child classes to provide specific database functionality for record retrieval, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being retrieved |
id | string | | The ID of the record to retrieve |
options | object | Additional options that may affect record retrieval |
- Source
- The result of the record retrieval
- Type:
- Promise.<object>
getVirtualFields(model) → {Array.<string>}
Utility method to get the virtual fields of a model. This is useful for operations that need to work with computed or derived properties.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance |
- Source
- Array of virtual field names
- Type:
- Array.<string>
(async) modelExists(model, options)
Checks if the model exists in the database.
Must be implemented by child classes to provide specific database functionality for model existence checking, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance to check for existence |
options | object | Additional options that may affect the existence check |
- Source
(async) removeRecord(model, id, options) → {Promise.<object>}
Removes a record for the given model by its ID.
Must be implemented by child classes to provide specific database functionality for record removal, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being removed |
id | string | | The ID of the record to remove |
options | object | Additional options that may affect record removal |
- Source
- The result of the record removal
- Type:
- Promise.<object>
sanitizeBody(model, body, partialopt) → {object}
Sanitizes the body of a record before creating or updating it. It ensures that all required fields are present and have valid values, and converts data types as necessary.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | DoboModel | The model instance for which the body is being sanitized | ||
body | object | The body of the record to be sanitized | ||
partial | boolean | <optional> | false | Indicates whether to perform a partial update |
- Source
- Sanitized body
- Type:
- object
(async) sanitizeConnection(conn) → {Promise.<void>}
Sanitize connection object
| Name | Type | Description |
|---|---|---|
conn | Object | Connection object |
- Source
- Type:
- Promise.<void>
sanitizeRecord(model, record) → {object}
Sanitizes a record retrieved from the database, converting data types as necessary and ensuring that the record conforms to the model's schema.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being sanitized |
record | object | The record retrieved from the database |
- Source
- Sanitized record
- Type:
- object
(async) transaction(model, handler, …args)
Executes a transaction for the given model.
Must be implemented by child classes to provide specific database functionality for transactions, or throw an error if the operation is not supported by the adapter.
| Name | Type | Attributes | Description |
|---|---|---|---|
model | DoboModel | The model instance for which the transaction is being executed | |
handler | function | The transaction handler function | |
args | any | <repeatable> | Additional arguments for the transaction handler |
- Source
(async) updateRecord(model, id, input, options) → {Promise.<object>}
Updates a record for the given model by its ID.
Must be implemented by child classes to provide specific database functionality for record updating, or throw an error if the operation is not supported by the adapter.
| Name | Type | Description |
|---|---|---|
model | DoboModel | The model instance for which the record is being updated |
id | string | | The ID of the record to update |
input | object | The input data for the update |
options | object | Additional options that may affect record updating |
- Source
- The result of the record update
- Type:
- Promise.<object>
Type Definitions
TIdField
- object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | <optional> | '_id' | The name of the ID field. |
type | string | <optional> | 'string' | The data type of the ID field. |
maxLength | number | <optional> | 50 | The maximum length of the ID field. |
required | boolean | <optional> | true | Indicates if the ID field is required. |
index | string | <optional> | 'primary' | The index type of the ID field. |
- Source
TSupport
- object
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
propType | object | <optional> | {} | An object indicating support for various property types. Properties
| ||||||||||||||||||||
search | boolean | <optional> | false | Indicates if search functionality is supported. | ||||||||||||||||||||
uniqueIndex | boolean | <optional> | false | Indicates if unique index functionality is supported. | ||||||||||||||||||||
nullableField | boolean | <optional> | true | Indicates if nullable fields are supported. | ||||||||||||||||||||
transaction | boolean | <optional> | false | Indicates if transaction functionality is supported. |
- Source