Constructor
new MutateModel(database, escaper, queryExecuter, model)
Initialize the instance.
Parameters:
Name | Type | Description |
---|---|---|
database |
Database | The database to mutate from. |
escaper |
Escaper | An instance of an Escaper matching the database type (e.g. MySQLEscaper). |
queryExecuter |
QueryExecuter | A QueryExecuter instance that implements the mutate (update or delete) method. |
model |
Object | A model object to mutate. Each key in the object should map to a table. The value associated with the key should be an object or an array of objects wherein each key maps to a column. The primary key is required for each model. |
- Source:
Extends
Members
database
Properties:
Name | Type | Description |
---|---|---|
database |
Database | A database instance. |
escaper |
Escaper | An instance of an Escaper class that can escape query parts. |
queryExecuter |
QueryExecuter | An instance of a QueryExecuter that can execute CRUD operations. |
- Inherited From:
- Source:
queries :Array.<Query>
An array of Query instances, one per model.
Type:
- Array.<Query>
- Source:
Methods
buildQuery() → {Query~QueryMeta}
Build the query.
- Inherited From:
- Source:
Returns:
The string-representation of the query to
execute along with any query parameters.
- Type
- Query~QueryMeta
createQuery(meta) → {Query}
Create a Query instance. Subclasses should specialize this method, as
this only creates the From portion of the query.
Parameters:
Name | Type | Description |
---|---|---|
meta |
ModelTraverse~ModelMeta | A meta object as created by the modelTraverse class. |
- Source:
Returns:
A Query instance representing the mutation query.
- Type
- Query
execute() → {Promise.<object>}
Execute the query.
- Source:
Returns:
A promise that will be resolved with an
object. The object will have an affectedRows property. If an error
occurs when executing a query, the promise shall be rejected with the
error unmodified.
- Type
- Promise.<object>
toString() → {string}
Create the SQL for each query.
- Source:
Returns:
A SQL string representing the mutation queries.
- Type
- string