delete method

Future<MySqlResult> delete(
  1. MySQLConnection conn,
  2. Sqler query
)

Executes a DELETE query on the table.

Executes the provided query to delete records from the table. The method includes a safety check to ensure the query contains a DELETE statement.

Parameters:

  • conn - The active MySQL database connection
  • query - A Sqler object representing the DELETE query to execute

Returns a MySqlResult containing information about the delete operation, including the number of affected rows.

Throws an Exception if the query doesn't contain a DELETE statement.

Example:

var query = Sqler()
  ..delete(QField('users'))
  ..where(WhereOne(QField('active'), QO.EQ, QVar(false)));
var result = await table.delete(conn, query);

Implementation

Future<MySqlResult> delete(MySQLConnection conn, Sqler query) async {
  String sql = query.toSQL();

  if (!sql.contains('DELETE')) {
    throw Exception(
        'Use delete method instead of select for deleting records.');
  }

  return execute(conn, sql);
}