Как выбрать DISTINCT записи в SQLite Flutter с помощью whereArgs? - PullRequest
0 голосов
/ 30 мая 2020
• 1000 добиться этого?

1 Ответ

1 голос
/ 30 мая 2020

При работе с пакетом SQFlite вы можете использовать query или rawQuery для выполнения этого, в обоих случаях вам нужно передать where arguments как array, а для distinct operator это можно сделать следующим образом:

  /// [GET] Get all the data by date using a query
  getData(String date) async {
    final db = await database;
    final response = await db.query(
      "TableExample",
      distinct: true,
      orderBy: 'id',
      where: 'date = ?',
      whereArgs: [date],
    );
    //...
  }

  /// [GET] Get all the data by date using a rawQuery
  getDailyPollResponsesPerRangeDate(String date) async {
    final db = await database;
    final response = await db.rawQuery(
      "SELECT DISTINCT TableExample.id, TableExample.date "
      "FROM TableExample "
      "WHERE TableExample.date == ? "
      "ORDER BY TableExample.date DESC",
      [date],
    );
    //...
  }
...