Members
adapter :string|null
The default database engine to use.
- string |
null
- Default Value
- null
idField :external:TAdapterIdField
Default ID field configuration for models.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | <optional> | 'id' | The name of the ID field |
type | string | <optional> | 'integer' | The data type of the ID field |
required | boolean | <optional> | true | Whether the ID field is required |
autoInc | boolean | <optional> | true | Whether the ID field is auto-incremented |
index | string | <optional> | 'primary' | The index type for the ID field |
propertyKeys :TPropertyKeys
Allowed property keys for model properties.
- TPropertyKeys
Methods
(async) buildModel(model, optionsopt) → {Promise.<external:TAdapterResult>}
Build the model's table in the database based on its properties and indexes.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the result of the build operation
- Type:
- Promise.<external:TAdapterResult>
(async) clearRecord(model, optionsopt) → {Promise.<external:TAdapterResult>}
Clear all records from the model's table in the database.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the result of the clear operation
- Type:
- Promise.<external:TAdapterResult>
(async) connect(connectionopt, noRebuildopt)
Connect to the database using the provided connection.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
connection | Object | <optional> | {} | The database connection object |
noRebuild | boolean | <optional> | false | Whether to skip rebuilding the connection |
(async) countRecord(model, filter, optionsopt) → {Promise.<external:TAdapterResult>}
Count records in the model's table in the database matching the filter.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
filter | Object | The filter criteria | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the count of matching records
- Type:
- Promise.<external:TAdapterResult>
(async) createAggregate(model, filter, params, optionsopt) → {Promise.<external:TAdapterResult>}
Create an aggregate query on the model's table in the database.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
filter | Object | The filter criteria | ||
params | Object | The aggregate parameters | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the aggregate result
- Type:
- Promise.<external:TAdapterResult>
(async) createHistogram(model, filter, params, optionsopt) → {Promise.<external:TAdapterResult>}
Create a histogram query on the model's table in the database.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
filter | Object | The filter criteria | ||
params | Object | The histogram parameters | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the histogram result
- Type:
- Promise.<external:TAdapterResult>
(async) findAllRecord(model, filter, optionsopt) → {Promise.<external:TAdapterResult>}
Find all records in the model's table in the database matching the filter.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
filter | Object | The filter criteria | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the found record(s)
- Type:
- Promise.<external:TAdapterResult>
(async) findRecord(model, filter, optionsopt) → {Promise.<external:TAdapterResult>}
Find record(s) in the model's table in the database matching the filter.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
filter | Object | The filter criteria | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the found record(s)
- Type:
- Promise.<external:TAdapterResult>
getClient(model, optionsopt) → {Object}
Get the database client for the given model and options.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
options | external:TOptions | <optional> | {} | Additional options |
The database client
- Type:
- Object
(async) getCreatedRecord(model, body, result, optionsopt) → {Promise.<external:TAdapterResult>}
Get newly created record. This is the case for mysql, other DB that doesn't support returning should extend this method
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
body | Object | The data used to create the record | ||
result | Object | The result returned from the database | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the newly created record
- Type:
- Promise.<external:TAdapterResult>
(async) getRawResult(instance, item) → {Promise.<Array>}
Get the raw result from the database for the given query instance and item.
| Name | Type | Description |
|---|---|---|
instance | Object | The query instance |
item | Object | The SQL query item |
The raw result from the database
- Type:
- Promise.<Array>
(async) getRecord(model, id, optionsopt) → {Promise.<external:TAdapterResult>}
Get a record from the model's table in the database by its ID.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
id | number | | The ID of the record to retrieve | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the retrieved record
- Type:
- Promise.<external:TAdapterResult>
(async) modelExists(model, optionsopt) → {Promise.<external:TAdapterResult>}
Check if the model's table exists in the database.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the existence status of the table
- Type:
- Promise.<external:TAdapterResult>
(async) removeRecord(model, id, optionsopt) → {Promise.<external:TAdapterResult>}
Remove a record from the model's table in the database by its ID.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
id | number | | The ID of the record to remove | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the old data
- Type:
- Promise.<external:TAdapterResult>
(async) transaction(model, handler, …args) → {Promise.<*>}
Execute a transaction on the model's database connection.
| Name | Type | Attributes | Description |
|---|---|---|---|
model | external:DoboModel | The model instance | |
handler | function | The transaction handler function | |
args | any | <repeatable> | Additional arguments to pass to the handler |
The result of the transaction
- Type:
- Promise.<*>
(async) updateRecord(model, id, body, optionsopt) → {Promise.<external:TAdapterResult>}
Update a record in the model's table in the database by its ID.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | external:DoboModel | The model instance | ||
id | number | | The ID of the record to update | ||
body | Object | The data to update the record with | ||
options | external:TOptions | <optional> | {} | Additional options |
An object containing the updated record and the old data
- Type:
- Promise.<external:TAdapterResult>
Type Definitions
TConnectionOptions
- Object |
external:TConnectionOptions
| Name | Type | Attributes | Description |
|---|---|---|---|
host | string | <optional> | The database host |
port | number | <optional> | The database port |
user | string | <optional> | The database user |
password | string | <optional> | The database password |
database | string | <optional> | The database name |
TPropertyKeys
- Array.<string>
| Name | Type | Description |
|---|---|---|
0 | string | specificType |
1 | string | precision |
2 | string | textType |
3 | string | scale |
4 | string | unsigned |
5 | string | comment |
6 | string | autoInc |