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
21 changes: 20 additions & 1 deletion docs/06-concepts/03-data-and-the-database/02-database/02-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ var products = await Product.db.upsert(
);
```

The result contains one row per input, in the same order. When `updateWhere` is set, conflicting rows that do not match are skipped and left out of the result, so the list can be shorter than the input. Pass `noReturn: true` to skip returning rows entirely for large batches.
The result contains one row per input, in the same order. When `updateWhere` is set, conflicting rows that do not match are skipped and left out of the result, so the list can be shorter than the input. For large batches, the read-back can be skipped entirely; see [Skipping returned rows](#skipping-returned-rows).

A single-row upsert that unexpectedly matches multiple rows throws a `DatabaseUpsertRowException`. See [exceptions](exceptions).

Expand Down Expand Up @@ -317,6 +317,25 @@ var companiesDeleted = await Company.db.deleteWhere(

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.

## Skipping returned rows

The batch and filtered write methods read the affected rows back from the database and return them as a list. Pass `noReturn: true` when the write itself is all you need.

```dart
await Company.db.updateWhere(
session,
columnValues: (t) => [t.name('Archived company')],
where: (t) => t.name.like('%Ltd'),
noReturn: true,
);
```

The write runs with the same filters, conflict handling, transaction, and atomicity guarantees, but the method returns an empty list instead of reading the rows back. Skipping that read saves transferring and deserializing every affected row, which is worth it for bulk imports, cleanup jobs, and any write where the generated ids, database defaults, and updated values are not used afterwards.

The `noReturn` parameter is available on `insert`, `update`, `updateWhere`, `upsert`, `delete`, and `deleteWhere`. The single-row methods `insertRow`, `updateRow`, `upsertRow`, and `deleteRow` always return the affected row.

Since the result is empty, `orderBy` and `orderByList` have no visible effect on it. They still matter on filtered operations, where they decide which rows a `limit` or `offset` selects.

## Count

Count is a special type of query that helps counting the number of rows in the database that matches a specific [filter](./filtering).
Expand Down
Loading