Add `all()` extension to load all rows

This commit is contained in:
Simon Binder 2023-01-27 16:58:54 +01:00
parent 592a96bf7e
commit ba2a0280d3
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 16 additions and 0 deletions

View File

@ -2,6 +2,7 @@
- Add `isExp`, `isValue`, `isNotExp` and `isNotValue` methods to `Expression` - Add `isExp`, `isValue`, `isNotExp` and `isNotValue` methods to `Expression`
to generate the `IS` operator in SQL. to generate the `IS` operator in SQL.
- Add `all()` extension on tables and views to quickly query all rows.
## 2.4.2 ## 2.4.2

View File

@ -4,6 +4,14 @@ import 'package:drift/drift.dart';
/// tables or views. /// tables or views.
extension TableOrViewStatements<Tbl extends HasResultSet, Row> extension TableOrViewStatements<Tbl extends HasResultSet, Row>
on ResultSetImplementation<Tbl, Row> { on ResultSetImplementation<Tbl, Row> {
/// Selects all rows that are in this table.
///
/// The returned [Selectable] can be run once as a future with [Selectable.get]
/// or as an auto-updating stream with [Selectable.watch].
Selectable<Row> all() {
return select();
}
/// Composes a `SELECT` statement on the captured table or view. /// Composes a `SELECT` statement on the captured table or view.
/// ///
/// This is equivalent to calling [DatabaseConnectionUser.select]. /// This is equivalent to calling [DatabaseConnectionUser.select].

View File

@ -43,4 +43,11 @@ void main() {
const TodoWithCategoryViewData( const TodoWithCategoryViewData(
description: 'category description', title: 'title')); description: 'category description', title: 'title'));
}); });
test('all()', () async {
final user = await db.users.insertReturning(
UsersCompanion.insert(name: 'Test user', profilePicture: Uint8List(0)));
expect(await db.users.all().get(), [user]);
});
} }