-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate sqlparser #361
Integrate sqlparser #361
Changes from all commits
2a2fd87
4f1d20d
a174323
620cd9a
9416a18
7ec04ce
34ceedb
fc5a2c2
3d859a9
94aeac2
73b7192
0efaecd
bbb846a
513eabf
956537a
09d50fe
804cd78
5792c69
6923120
523211d
8bb6fbc
9c49c9e
431c996
f920a07
3897bf9
0af2a9c
be29dc0
352d75b
7b7b732
98df943
c802294
7da688e
6634f3b
8279bbe
2c3d326
6d8cc21
9925320
1d2a210
6ac8111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -134,6 +134,33 @@ void main() { | |||
|
||||
verify(mockDatabaseExecutor.rawQuery(sql, arguments)); | ||||
}); | ||||
|
||||
test('executes query with update', () async { | ||||
final streamController = StreamController<String>(); | ||||
const entityName = 'person'; | ||||
|
||||
final underTest = QueryAdapter(mockDatabaseExecutor, streamController); | ||||
|
||||
final arguments = [123]; | ||||
await underTest.queryNoReturn(sql, | ||||
arguments: arguments, changedEntities: {entityName}); | ||||
|
||||
expect(streamController.stream, emits(entityName)); | ||||
verify(mockDatabaseExecutor.rawQuery(sql, arguments)); | ||||
|
||||
await streamController.close(); | ||||
}); | ||||
|
||||
test('executes query with update with no _changeListener present', | ||||
() async { | ||||
const entityName = 'person'; | ||||
|
||||
final arguments = [123]; | ||||
await underTest.queryNoReturn(sql, | ||||
arguments: arguments, changedEntities: {entityName}); | ||||
|
||||
verify(mockDatabaseExecutor.rawQuery(sql, arguments)); | ||||
}); | ||||
}); | ||||
}); | ||||
|
||||
|
@@ -162,7 +189,7 @@ void main() { | |||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryStream(sql, | ||||
queryableName: entityName, isView: false, mapper: mapper); | ||||
dependencies: {entityName}, mapper: mapper); | ||||
|
||||
expect(actual, emits(person)); | ||||
}); | ||||
|
@@ -179,8 +206,7 @@ void main() { | |||
final actual = underTest.queryStream( | ||||
sql, | ||||
arguments: arguments, | ||||
queryableName: entityName, | ||||
isView: false, | ||||
dependencies: {entityName}, | ||||
mapper: mapper, | ||||
); | ||||
|
||||
|
@@ -195,7 +221,7 @@ void main() { | |||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryStream(sql, | ||||
queryableName: entityName, isView: false, mapper: mapper); | ||||
dependencies: {entityName}, mapper: mapper); | ||||
streamController.add(entityName); | ||||
|
||||
expect(actual, emitsInOrder(<Person>[person, person])); | ||||
|
@@ -211,7 +237,7 @@ void main() { | |||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryListStream(sql, | ||||
queryableName: entityName, isView: false, mapper: mapper); | ||||
dependencies: {entityName}, mapper: mapper); | ||||
|
||||
expect(actual, emits([person, person2])); | ||||
}); | ||||
|
@@ -230,8 +256,7 @@ void main() { | |||
final actual = underTest.queryListStream( | ||||
sql, | ||||
arguments: arguments, | ||||
queryableName: entityName, | ||||
isView: false, | ||||
dependencies: {entityName}, | ||||
mapper: mapper, | ||||
); | ||||
|
||||
|
@@ -248,7 +273,7 @@ void main() { | |||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryListStream(sql, | ||||
queryableName: entityName, isView: false, mapper: mapper); | ||||
dependencies: {entityName}, mapper: mapper); | ||||
streamController.add(entityName); | ||||
|
||||
expect( | ||||
|
@@ -262,6 +287,7 @@ void main() { | |||
|
||||
test('query stream from view with same and different triggering entity', | ||||
() async { | ||||
const otherEntity = 'otherEntity'; | ||||
final person = Person(1, 'Frank'); | ||||
final person2 = Person(2, 'Peter'); | ||||
final queryResult = Future(() => [ | ||||
|
@@ -271,7 +297,7 @@ void main() { | |||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryListStream(sql, | ||||
queryableName: entityName, isView: true, mapper: mapper); | ||||
dependencies: {entityName, otherEntity}, mapper: mapper); | ||||
expect( | ||||
actual, | ||||
emitsInOrder(<List<Person>>[ | ||||
|
@@ -282,7 +308,36 @@ void main() { | |||
); | ||||
|
||||
streamController.add(entityName); | ||||
streamController.add('otherEntity'); | ||||
streamController.add(otherEntity); | ||||
}); | ||||
|
||||
test('unrelated update should not update stream', () async { | ||||
const otherEntity = 'otherEntity'; | ||||
final person = Person(1, 'Frank'); | ||||
final person2 = Person(2, 'Peter'); | ||||
final queryResult = Future(() => [ | ||||
<String, dynamic>{'id': person.id, 'name': person.name}, | ||||
<String, dynamic>{'id': person2.id, 'name': person2.name}, | ||||
]); | ||||
when(mockDatabaseExecutor.rawQuery(sql)).thenAnswer((_) => queryResult); | ||||
|
||||
final actual = underTest.queryListStream(sql, | ||||
dependencies: {entityName}, mapper: mapper); | ||||
//first, emit the result | ||||
expect( | ||||
actual, | ||||
emitsInOrder(<List<Person>>[ | ||||
[person, person2], | ||||
])); | ||||
|
||||
//after emitting the first result, no other updates were made | ||||
expect(actual.skip(1), emitsDone); | ||||
|
||||
streamController.add(otherEntity); | ||||
streamController.add(otherEntity); | ||||
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100)); | ||||
await streamController.close(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 We can remove this line as we close
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remove that, the test will fail because of a deadlock/timeout, since the |
||||
}); | ||||
}); | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ The query parser, in the future, will allows us to parse
@Query
results into non-primitive values, right? #94There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need another PR but it should be as simple as adding another Queryable subtype and using the same processing as for entities/views. The type checking and the mapping already exists.