Skip to content

Commit

Permalink
Add deleteEntity method
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Oct 15, 2024
1 parent d02307b commit c1651bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

* Add `deleteEntity` in case the caller does not have access to the primary key used by the connector (e.g. if it's a combined one)

## 1.1.0

* Adds reactivity
Expand Down
4 changes: 4 additions & 0 deletions lib/src/index_entity_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class IndexedEntityStore<T, K> {
deleteMany({key});
}

void deleteEntity(T entity) {
delete(_connector.getPrimaryKey(entity));
}

void deleteMany(Set<K> keys) {
for (final key in keys) {
_database.execute(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: indexed_entity_store
description: A fast, simple, and synchronous entity store for Flutter applications.
version: 1.1.0
version: 1.1.1
repository: https://github.com/LunaONE/indexed_entity_store

environment:
Expand Down
10 changes: 7 additions & 3 deletions test/indexed_entity_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ void main() {
expect(fooByQueryValueNotExists.value, isEmpty);

// add another one only matching the _all_ query
fooStore.insert(
_FooEntity(id: 2, valueA: 'something_else', valueB: 2, valueC: true),
final entity2 = _FooEntity(
id: 2,
valueA: 'something_else',
valueB: 2,
valueC: true,
);
fooStore.insert(entity2);

expect(allFoos.value, hasLength(2));
expect(fooById1.value, isA<_FooEntity>());
Expand All @@ -219,7 +223,7 @@ void main() {
fooByQueryValueNotExists.dispose();

// No more subscriptions, so this has no effect
fooStore.delete(2);
fooStore.deleteEntity(entity2);

expect(fooStore.subscriptionCount, 0);
},
Expand Down

0 comments on commit c1651bd

Please sign in to comment.