-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.dart
24 lines (21 loc) · 1 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Emits a single row, doesn't emit if the row dosen't exist.
Stream<MyEntry> singleQuery = streamDb.createQuery("MyTable", where: 'id = ?', whereArgs: [id])
.mapToOne((row) => MyEntry(row));
// Emits a single row, or the given default value if the row doesn't exist.
Stream<MyEntry> singleOrDefaultQuery = streamDb.createQuery("MyTable", where: 'id = ?', whereArgs: [id])
.mapToOneOrDefault((row) => MyEntry(row), MyEntry.empty());
// Emits a list of rows.
Stream<List<MyEntry>> listQuery = streamDb.createQuery("MyTable", where: 'name LIKE ?', whereArgs: [query])
.mapToList((row) => MyEntry(row));
var flexibleQuery = streamDb.createQuery("MyTable", where: 'name LIKE ?', whereArgs: [query])
.asyncMap((query) => {
// query is lazy, this lets you not even execute it if you don't need to.
if (condition) {
return query();
} else {
return Stream.empty();
}
}).map((rows) {
// Do something with all the rows.
return ...;
});