part of '../query_builder.dart'; /// A `DELETE` statement in sql class DeleteStatement extends Query with SingleTableQueryMixin { /// This constructor should be called by [DatabaseConnectionUser.delete] for /// you. DeleteStatement(DatabaseConnectionUser database, TableInfo table) : super(database, table); @override void writeStartPart(GenerationContext ctx) { ctx.buffer.write('DELETE FROM ${table.$tableName}'); } /// Deletes just this entity. May not be used together with [where]. /// /// Returns the amount of rows that were deleted by this statement directly /// (not including additional rows that might be affected through triggers or /// foreign key constraints). Future delete(Insertable entity) { assert( whereExpr == null, 'When deleting an entity, you may not use where(...)' 'as well. The where clause will be determined automatically'); whereSamePrimaryKey(entity); return go(); } /// Deletes all rows matched by the set [where] clause and the optional /// limit. /// /// Returns the amount of rows that were deleted by this statement directly /// (not including additional rows that might be affected through triggers or /// foreign key constraints). Future go() async { final ctx = constructQuery(); return ctx.executor!.doWhenOpened((e) async { final rows = await e.runDelete(ctx.sql, ctx.boundVariables); if (rows > 0) { database.notifyUpdates( {TableUpdate.onTable(table, kind: UpdateKind.delete)}); } return rows; }); } }