Skip to main content

Update

Performs a query to update data in a table.

Possible crash

To prevent accidental update of all rows, this will throw an error on execute() if no where() was defined.

To enable the update of all rows use force().

Methods

data()

→ (object = Object) → this

Updates all matching rows with the given object.

Parameters

ParameterTypeDescription
objectObjectThe object with the data to update to. Keys represent column names.

Returns

this


selectDatabase()

→ (database = String) → this

Selects a different database for this query.

Parameters

ParameterTypeDescription
databaseStringName of the database to select

Returns

this


force()

→ () → this

Enables update of all rows.

Returns

this


where()

→ (string = String, values = Array<any>) → this

Adds a where-clause to the query

  • Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
  • If you are using joins, specify the table and column together: table.column

Parameters

ParameterTypeDescription
stringStringThe where-clause as a string with ? representing each values.
valuesArray<any>Array containing values replacing the ? in the string (from left to right)

Returns

this


execute()

async → () → OkPacket

Executes the prepared query.

Returns

OkPacket