Skip to content

Commit

Permalink
Explicit precedence when using 3 or more filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Dec 26, 2024
1 parent e571cf3 commit acd7147
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

* Use explicit precedence, fixing a potential issue when using 3 or more filters

## 2.0.1

* Add tests for internal schema migrations
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.1"
version: "2.0.2"
leak_tracker:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _AndQuery extends Query {
@override
(String, List<dynamic>) _entityKeysQuery() {
return (
' ${first._entityKeysQuery().$1} INTERSECT ${second._entityKeysQuery().$1} ',
' SELECT * FROM ( ${first._entityKeysQuery().$1} INTERSECT ${second._entityKeysQuery().$1} ) ',
[...first._entityKeysQuery().$2, ...second._entityKeysQuery().$2],
);
}
Expand All @@ -38,7 +38,7 @@ class _OrQuery extends Query {
@override
(String, List<dynamic>) _entityKeysQuery() {
return (
' ${first._entityKeysQuery().$1} UNION ${second._entityKeysQuery().$1} ',
' SELECT * FROM ( ${first._entityKeysQuery().$1} UNION ${second._entityKeysQuery().$1} ) ',
[...first._entityKeysQuery().$2, ...second._entityKeysQuery().$2],
);
}
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: 2.0.1
version: 2.0.2
repository: https://github.com/LunaONE/indexed_entity_store

environment:
Expand Down
46 changes: 44 additions & 2 deletions test/indexed_entity_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,50 @@ void main() {
hasLength(2),
);

// delete initial
fooStore.delete(key: 99);
// add a third entity with different values
fooStore.write(
_FooEntity(id: 999, valueA: 'aaa', valueB: 22, valueC: true),
);

expect(
fooStore.queryOnce(where: (cols) => cols['b'].greaterThanOrEqual(2)),
hasLength(3),
);
expect(
fooStore.queryOnce(
where: (cols) => cols['b'].greaterThan(2) & cols['b'].lessThan(22),
),
isEmpty,
);
expect(
fooStore.queryOnce(
where: (cols) => cols['b'].greaterThan(1) & cols['b'].lessThan(22),
),
hasLength(2),
);
expect(
fooStore.queryOnce(
where: (cols) =>
cols['b'].greaterThan(1) & cols['b'].lessThanOrEqual(22),
),
hasLength(3),
);
expect(
fooStore.queryOnce(
where: (cols) =>
cols['b'].greaterThan(2) & cols['b'].lessThanOrEqual(22),
),
hasLength(1),
);
expect(
fooStore.queryOnce(
where: (cols) => cols['b'].greaterThan(2),
),
hasLength(1),
);

// delete initial & latest
fooStore.delete(keys: [99, 999]);
expect(fooStore.queryOnce(), hasLength(1));
expect(
fooStore.queryOnce(where: (cols) => cols['a'].equals('a')),
Expand Down

0 comments on commit acd7147

Please sign in to comment.