Skip to main content

Delete

Performs a query to delete rows from a table.

Possible crash

To prevent accidental deletion of all rows, an error will be thrown on execute() if no where() clause is defined.

To explicitly allow deletion of all rows, use force().


Methods


selectDatabase()

→ (database = String) → this

Sets the database for this query.

Parameters

ParameterTypeDescription
databaseStringThe database name to select.

Returns

this


where()

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

Addsa WHERE clause to the delete query.

  • Use placeholders (?) in the condition string and provide values in the values array to prevent SQL injection.
  • If using joins, specify the table and column together: "table.column".

Parameters

ParameterTypeDescription
stringStringSQL WHERE condition with ? placeholders.
valuesArray<any>Values replacing ?, in left-to-right order.

Example Usage

.delete().where("id = ?", [5])

Returns

this


force()

→ () → this

Enables deletion of all rows, overriding the safeguard in execute().

Use with Caution

Calling execute() after force() will delete all rows in the table.

Returns

this


execute()

async → () → OkPacket

Executes the prepared DELETE query.

Returns

OkPacket