@@ -2,6 +2,7 @@ import "package:test/test.dart";
22import "package:objectbox/objectbox.dart" ;
33import "entity.dart" ;
44import 'test_env.dart' ;
5+ import "package:objectbox/src/bindings/constants.dart" show OBXOrderFlag;
56
67void main () {
78 TestEnv env;
@@ -356,6 +357,41 @@ void main() {
356357 }
357358 });
358359
360+ test (".order queryBuilder" , () {
361+ box.put (TestEntity .initText ("World" ));
362+ box.put (TestEntity .initText ("Hello" ));
363+ box.put (TestEntity .initText ("HELLO" ));
364+ box.put (TestEntity .initText ("World" ));
365+ box.put (TestEntity .initText ("Goodbye" ));
366+ box.put (TestEntity .initText ("Cruel" ));
367+ box.put (TestEntity .initInteger (1337 ));
368+
369+ final text = TestEntity_ .text;
370+
371+ final condition = text.notNull ();
372+
373+ final query = box.query (condition)
374+ .order (text)
375+ .build ();
376+
377+ final queryWithFlags = box.query (condition)
378+ .order (text, flags: OBXOrderFlag .DESCENDING | OBXOrderFlag .CASE_SENSITIVE )
379+ .build ();
380+
381+ final result1 = query.find ().map ((e) => e.text).toList ();
382+ final result2 = queryWithFlags.find ().map ((e) => e.text).toList ();
383+
384+ expect ("Cruel" , result1[0 ]);
385+ expect ("World" , result2[0 ]);
386+ expect ("Hello" , result1[2 ]);
387+ expect ("Hello" , result2[2 ]);
388+ expect ("HELLO" , result1[3 ]);
389+ expect ("HELLO" , result2[3 ]);
390+
391+ query.close ();
392+ queryWithFlags.close ();
393+ });
394+
359395 tearDown (() {
360396 env.close ();
361397 });
0 commit comments