objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence

Home Page:https://docs.objectbox.io/getting-started

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to use aggregate function like SUM

rodriger06 opened this issue · comments

Hi everyone,

I am trying to use aggregate function in my query but it looks like i am not able to see the function .
below is my code

import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import '../../../../objectbox.g.dart';
import '../../../income/data/models/income.dart';

class ObjectBox {
  /// The Store of this app.
  late final Store store;
  late final Box<Income> incomeBox;

  late final Stream<Query<double>> balanceQueryStream;
  late final balanceBuilder;

  ObjectBox._create(this.store) {
    // Add any additional setup code, e.g. build queries.
    incomeBox = Box<Income>(store);
  }

  /// Create an instance of ObjectBox to use throughout the app.
  static Future<ObjectBox> create() async {
    final docsDir = await getApplicationDocumentsDirectory();
    final store = await openStore(directory: p.join(docsDir.path, "obx-example"));
    return ObjectBox._create(store);
  }



  void getCurrentBalance() {
    balanceBuilder = incomeBox.query((Income_.monthNumber.equals(0)));
    balanceBuilder.watch(triggerImmediately: true);
  }
}

in my function called getCurrentBalance() i want to sum my result set. i tried the following but android studio complains that sum function is undefined

    balanceBuilder = incomeBox.query((Income_.monthNumber.equals(0))).sum(Income_.actualAmount);

i get error message such as The method 'sum' isn't defined for the type 'QueryBuilder'.
can someone help please? am i doing something wrong? how can i fix my code to work properly.

Aggregating results only works for a property query, see the docs on how to build one.

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.