From 97855f4bf446732a86979128b4213e51af93c04c Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 17:46:56 +0800 Subject: [PATCH 1/6] fix_multi_order_by --- packages/orm/angel_orm/lib/src/query.dart | 5 +++-- packages/orm/angel_orm_test/lib/src/join_test.dart | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index 91f6980f..9e4d72fa 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -331,8 +331,9 @@ abstract class Query extends QueryBase { b.write(' WHERE $whereClause'); } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); - for (var item in _orderBy) { - b.write(' ORDER BY ${item.compile()}'); + var orderByClause = _orderBy.map(item.compile()).join(', '); + if (orderByClause?.isNotEmpty == true) { + b.write(' ORDER BY $orderByClause'); } if (_limit != null) b.write(' LIMIT $_limit'); if (_offset != null) b.write(' OFFSET $_offset'); diff --git a/packages/orm/angel_orm_test/lib/src/join_test.dart b/packages/orm/angel_orm_test/lib/src/join_test.dart index b380de64..630bf156 100644 --- a/packages/orm/angel_orm_test/lib/src/join_test.dart +++ b/packages/orm/angel_orm_test/lib/src/join_test.dart @@ -80,4 +80,12 @@ void joinTests(FutureOr Function() createExecutor, element.personAge == originalPerson?.age), true); }); + + test('select orders with multi order by fields', () async { + var query = PersonOrderQuery(); + query.orderBy(PersonOrderFields.personId, descending: true); + query.orderBy(PersonOrderFields.id, descending: true); + var orders = await query.get(executor); + expect(orders.first.personId > orders.last.personId, true); + }); } From 63b7c53d7f242a837a82c08ce974676ad2a5d799 Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 17:53:14 +0800 Subject: [PATCH 2/6] fix multi order by error --- packages/orm/angel_orm/lib/src/query.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index 9e4d72fa..cff833c4 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -331,7 +331,7 @@ abstract class Query extends QueryBase { b.write(' WHERE $whereClause'); } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); - var orderByClause = _orderBy.map(item.compile()).join(', '); + var orderByClause = _orderBy.map((order) => order.compile()).join(', '); if (orderByClause?.isNotEmpty == true) { b.write(' ORDER BY $orderByClause'); } From 8a698f79a7d19d38bc176d16dd130fb9c9cabead Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 17:58:22 +0800 Subject: [PATCH 3/6] format code --- packages/orm/angel_orm/lib/src/query.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index cff833c4..f9d77569 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -332,7 +332,7 @@ abstract class Query extends QueryBase { } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); var orderByClause = _orderBy.map((order) => order.compile()).join(', '); - if (orderByClause?.isNotEmpty == true) { + if (orderByClause.isNotEmpty == true) { b.write(' ORDER BY $orderByClause'); } if (_limit != null) b.write(' LIMIT $_limit'); From d8dcfe8bef09a7e55daf079c35447e6de7cf94e7 Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 18:03:25 +0800 Subject: [PATCH 4/6] fix error --- packages/orm/angel_orm_test/lib/src/join_test.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/orm/angel_orm_test/lib/src/join_test.dart b/packages/orm/angel_orm_test/lib/src/join_test.dart index 630bf156..27512d72 100644 --- a/packages/orm/angel_orm_test/lib/src/join_test.dart +++ b/packages/orm/angel_orm_test/lib/src/join_test.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:math'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:test/test.dart'; @@ -86,6 +85,6 @@ void joinTests(FutureOr Function() createExecutor, query.orderBy(PersonOrderFields.personId, descending: true); query.orderBy(PersonOrderFields.id, descending: true); var orders = await query.get(executor); - expect(orders.first.personId > orders.last.personId, true); + expect(orders.first.personId! > orders.last.personId!, true); }); } From abc1153076b505679eda63635f8b994deb4d0dbe Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 18:08:13 +0800 Subject: [PATCH 5/6] fix action error --- packages/orm/angel_orm_test/lib/src/join_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/orm/angel_orm_test/lib/src/join_test.dart b/packages/orm/angel_orm_test/lib/src/join_test.dart index 27512d72..efe4c969 100644 --- a/packages/orm/angel_orm_test/lib/src/join_test.dart +++ b/packages/orm/angel_orm_test/lib/src/join_test.dart @@ -82,9 +82,9 @@ void joinTests(FutureOr Function() createExecutor, test('select orders with multi order by fields', () async { var query = PersonOrderQuery(); - query.orderBy(PersonOrderFields.personId, descending: true); query.orderBy(PersonOrderFields.id, descending: true); + query.orderBy(PersonOrderFields.personId, descending: true); var orders = await query.get(executor); - expect(orders.first.personId! > orders.last.personId!, true); + expect(orders.first.idAsInt > orders.last.idAsInt, true); }); } From 9637c25a97c894b914aa9aff17f14d42e78d0de9 Mon Sep 17 00:00:00 2001 From: debuggerx01 Date: Tue, 11 Jan 2022 19:27:50 +0800 Subject: [PATCH 6/6] Update query.dart clean code --- packages/orm/angel_orm/lib/src/query.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index f9d77569..1e4f6e81 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -332,7 +332,7 @@ abstract class Query extends QueryBase { } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); var orderByClause = _orderBy.map((order) => order.compile()).join(', '); - if (orderByClause.isNotEmpty == true) { + if (orderByClause.isNotEmpty) { b.write(' ORDER BY $orderByClause'); } if (_limit != null) b.write(' LIMIT $_limit');