From 80f854612275799aa269ca1ab4fda9a2af21cddc Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 28 Aug 2022 22:39:07 +0200 Subject: [PATCH] Add tests for null sorting on asc/desc factories --- docs/pages/docs/Examples/existing_databases.md | 1 - .../src/runtime/query_builder/components/order_by.dart | 4 ++-- drift/test/database/statements/order_by_test.dart | 10 ++++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/pages/docs/Examples/existing_databases.md b/docs/pages/docs/Examples/existing_databases.md index d7ebb7054..07a8a4002 100644 --- a/docs/pages/docs/Examples/existing_databases.md +++ b/docs/pages/docs/Examples/existing_databases.md @@ -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 diff --git a/drift/lib/src/runtime/query_builder/components/order_by.dart b/drift/lib/src/runtime/query_builder/components/order_by.dart index cc81cf9c1..4bd5392a9 100644 --- a/drift/lib/src/runtime/query_builder/components/order_by.dart +++ b/drift/lib/src/runtime/query_builder/components/order_by.dart @@ -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, @@ -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, diff --git a/drift/test/database/statements/order_by_test.dart b/drift/test/database/statements/order_by_test.dart index 77ba9b809..1c76d1a64 100644 --- a/drift/test/database/statements/order_by_test.dart +++ b/drift/test/database/statements/order_by_test.dart @@ -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')); + }); }