Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions docs/06-concepts/06-database/05-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,35 @@ The input object needs to have the `id` field set. The `deleteRow` method return

### Delete several rows

To batch delete several rows, use the `delete` method.
To batch delete several rows, use the `delete` method. This method also supports [ordering](sort) the returned deleted results.

```dart
var companiesDeleted = await Company.db.delete(session, companies);
var companiesDeleted = await Company.db.delete(
session,
companies,
orderBy: (t) => t.id,
orderDescending: false,
);
```

This is an atomic operation, meaning no entries will be deleted if any entry fails to be deleted. The `delete` method returns a `List` of the models deleted.
This is an atomic operation, meaning no entries will be deleted if any entry fails to be deleted. The `delete` method returns a `List` of the models deleted, ordered as specified by the orderBy.

### Delete by filter

You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method.
You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method. This method also supports [ordering](sort) of the returned deleted results.

```dart
var companiesDeleted = await Company.db.deleteWhere(
session,
where: (t) => t.name.like('%Ltd'),
orderByList: (t) => [
Order(column: t.name, orderDescending: true),
Order(column: t.id),
],
);
```

The above example will delete any row that ends in _Ltd_. The `deleteWhere` method returns a `List` of the models deleted.
The above example will delete any row where the `name` ends in _Ltd_. The `deleteWhere` method returns a `List` of the models deleted, ordered by name in descending order, followed by id in ascending order.

## Count

Expand Down
Loading