Skip to content

Commit

Permalink
Add tests for null sorting on asc/desc factories
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Aug 29, 2022
1 parent b399db7 commit 80f8546
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/pages/docs/Examples/existing_databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import 'package:drift/drift.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:path/path.dart' as p;


LazyDatabase _openConnection() {
return LazyDatabase(() async {
// put the database file, called db.sqlite here, into the documents folder
Expand Down
4 changes: 2 additions & 2 deletions drift/lib/src/runtime/query_builder/components/order_by.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class OrderingTerm extends Component {

/// Creates an ordering term that sorts for ascending values
/// of [expression] and the [nulls].
factory OrderingTerm.asc(Expression expression, [NullsOrder? nulls]) {
factory OrderingTerm.asc(Expression expression, {NullsOrder? nulls}) {
return OrderingTerm(
expression: expression,
mode: OrderingMode.asc,
Expand All @@ -63,7 +63,7 @@ class OrderingTerm extends Component {

/// Creates an ordering term that sorts for descending values
/// of [expression] and the [nulls].
factory OrderingTerm.desc(Expression expression, [NullsOrder? nulls]) {
factory OrderingTerm.desc(Expression expression, {NullsOrder? nulls}) {
return OrderingTerm(
expression: expression,
mode: OrderingMode.desc,
Expand Down
10 changes: 10 additions & 0 deletions drift/test/database/statements/order_by_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ void main() {
argThat(isEmpty),
));
});

test('works with helper factories', () {
final table = db.users;

expect(OrderingTerm.asc(table.id), generates('id ASC'));
expect(OrderingTerm.asc(table.id, nulls: NullsOrder.last),
generates('id ASC NULLS LAST'));
expect(OrderingTerm.desc(table.id, nulls: NullsOrder.first),
generates('id DESC NULLS FIRST'));
});
}

0 comments on commit 80f8546

Please sign in to comment.