DoboKnexAdapter

DoboKnexAdapter class definition.

Constructor

new DoboKnexAdapter()

Constructor

Members

adapter :string|null

The default database engine to use.

Type:
  • string | null
Default Value
  • null

idField :external:TAdapterIdField

Default ID field configuration for models.

Properties
NameTypeAttributesDefaultDescription
namestring<optional>
'id'

The name of the ID field

typestring<optional>
'integer'

The data type of the ID field

requiredboolean<optional>
true

Whether the ID field is required

autoIncboolean<optional>
true

Whether the ID field is auto-incremented

indexstring<optional>
'primary'

The index type for the ID field

propertyKeys :TPropertyKeys

Allowed property keys for model properties.

Type:
  • TPropertyKeys

Methods

(async) buildModel(model, optionsopt) → {Promise.<external:TAdapterResult>}

Build the model's table in the database based on its properties and indexes.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
connectionObject<optional>
{}

The database connection object

noRebuildboolean<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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

filterObject

The filter criteria

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

filterObject

The filter criteria

paramsObject

The aggregate parameters

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

filterObject

The filter criteria

paramsObject

The histogram parameters

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

filterObject

The filter criteria

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

filterObject

The filter criteria

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

bodyObject

The data used to create the record

resultObject

The result returned from the database

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeDescription
instanceObject

The query instance

itemObject

The SQL query item

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

idnumber | string

The ID of the record to retrieve

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

idnumber | string

The ID of the record to remove

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

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.

Parameters:
NameTypeAttributesDescription
modelexternal:DoboModel

The model instance

handlerfunction

The transaction handler function

argsany<repeatable>

Additional arguments to pass to the handler

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
modelexternal:DoboModel

The model instance

idnumber | string

The ID of the record to update

bodyObject

The data to update the record with

optionsexternal:TOptions<optional>
{}

Additional options

Returns:

An object containing the updated record and the old data

Type: 
Promise.<external:TAdapterResult>

Type Definitions

TConnectionOptions

Properties
NameTypeAttributesDescription
hoststring<optional>

The database host

portnumber<optional>

The database port

userstring<optional>

The database user

passwordstring<optional>

The database password

databasestring<optional>

The database name

TPropertyKeys

Type:
  • Array.<string>
Properties
NameTypeDescription
0string

specificType

1string

precision

2string

textType

3string

scale

4string

unsigned

5string

comment

6string

autoInc