Skip to main content

Update

Executes a query to update data in a table.

Possible Crash

To prevent accidental updates on all rows, this operation will throw an error when calling execute() if no where() clause is defined.

To explicitly allow updates on all rows, use force().


Methods


data()

→ (object = Object) → this

Updates all matching rows with the provided data.

Parameters

ParameterTypeDescription
objectObjectAn object where keys represent column names and values represent the new data.

Returns

this


selectDatabase()

→ (database = String) → this

Selects a different database for the query.

Parameters

ParameterTypeDescription
databaseStringThe name of the database to use for the update.

Returns

this


force()

→ () → this

Allows updates on all rows in the table.

Returns

this


where()

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

Adds a WHERE clause to filter the update query.

  • Use ? as placeholders in the condition string to prevent SQL injection.

Parameters

ParameterTypeDescription
stringStringThe WHERE clause with ? placeholders.
valuesArray<any>An arrray of values replacing the placeholders in left-to-right order.

Returns

this


execute()

async → () → OkPacket

Executes the prepared update query.

Returns

OkPacket