Skip to content

Commit

Permalink
fix: Update return type for delete operations. (#89)
Browse files Browse the repository at this point in the history
* fix: update return type documentation.

* fix: add documentation for delete interface change.
  • Loading branch information
SandPod authored Apr 11, 2024
1 parent a993a32 commit c3eb153
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/05-concepts/06-database/05-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,30 @@ To delete a single row, use the `deleteRow` method.

```dart
var company = await Company.db.findById(session, companyId); // Fetched company has its id set
var id = await Company.db.deleteRow(session, company);
var companyDeleted = await Company.db.deleteRow(session, company);
```
The input object needs to have the `id` field set. The `deleteRow` method returns the `id` of the deleted row.
The input object needs to have the `id` field set. The `deleteRow` method returns the deleted model.

### Delete several rows
To batch delete several rows, use the `delete` method.

```dart
var ids = await Company.db.delete(session, companies);
var companiesDeleted = await Company.db.delete(session, companies);
```

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 `id`s of the deleted row(s).
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.

### Delete by filter
You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method.

```dart
var ids = await Company.db.deleteWhere(
var companiesDeleted = await Company.db.deleteWhere(
session,
where: (t) => t.name.like('%Ltd'),
);
```

The above example will delete any row that ends in *Ltd*. The `deleteWhere` method returns a `List` of the `id`s of the deleted row(s).
The above example will delete any row that ends in *Ltd*. The `deleteWhere` method returns a `List` of the models deleted.

## Count

Expand Down
18 changes: 18 additions & 0 deletions docs/12-upgrading/01-upgrade-to-two.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ and if `result.map((row) => row.toColumnMap())` is used to format the result fro
]
```

### Update return type for delete operations

The return type for all delete operations has been changed from the `id` of the deleted rows to the actual deleted rows. This makes the return type for the delete operations consistent with the return type of the other database operations. It also dramatically simplifies retrieving and removing rows in concurrent environments.

Return type before the change:
```dart
int companyId = await Company.db.deleteRow(session, company);
List<int> companyIds = await Company.db.delete(session, [company]);
List<int> companyIds = await Company.db.deleteWhere(session, where: (t) => t.name.like('%Ltd'));
```

Return types after the change:
```dart
Company company = await Company.db.deleteRow(session, company);
List<Company> companies = await Company.db.delete(session, [company]);
List<Company> companies = await Company.db.deleteWhere(session, where: (t) => t.name.like('%Ltd'));
```

## Changes to database tables

### Integer representation changed to bigint
Expand Down

0 comments on commit c3eb153

Please sign in to comment.