1.7 KiB
1.7 KiB
| sidebar_position |
|---|
| 5 |
Delete
Performs a query to delete rows from a table.
:::warning 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
| Parameter | Type | Description |
|---|---|---|
database |
String | The 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 thevaluesarray to prevent SQL injection. - If using joins, specify the table and column together:
"table.column".
Parameters
| Parameter | Type | Description |
|---|---|---|
string |
String | SQL WHERE condition with ? placeholders. |
values |
Array<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().
:::danger 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