Skip to content

Commit a4bfb88

Browse files
authored
docs: Update documentation for ordering of batch delete returned results (#459)
1 parent 95e8d03 commit a4bfb88

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

docs/06-concepts/06-database/05-crud.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,35 @@ The input object needs to have the `id` field set. The `deleteRow` method return
231231

232232
### Delete several rows
233233

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

236236
```dart
237-
var companiesDeleted = await Company.db.delete(session, companies);
237+
var companiesDeleted = await Company.db.delete(
238+
session,
239+
companies,
240+
orderBy: (t) => t.id,
241+
orderDescending: false,
242+
);
238243
```
239244

240-
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.
245+
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.
241246

242247
### Delete by filter
243248

244-
You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method.
249+
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.
245250

246251
```dart
247252
var companiesDeleted = await Company.db.deleteWhere(
248253
session,
249254
where: (t) => t.name.like('%Ltd'),
255+
orderByList: (t) => [
256+
Order(column: t.name, orderDescending: true),
257+
Order(column: t.id),
258+
],
250259
);
251260
```
252261

253-
The above example will delete any row that ends in _Ltd_. The `deleteWhere` method returns a `List` of the models deleted.
262+
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.
254263

255264
## Count
256265

0 commit comments

Comments
 (0)