doCountSQL method

  1. @override
FutureOr<int> doCountSQL(
  1. String entityName,
  2. String table,
  3. SQL sql,
  4. Transaction transaction,
  5. PostgreSQLConnectionWrapper connection,
)
override

Implementation

@override
FutureOr<int> doCountSQL(String entityName, String table, SQL sql,
    Transaction transaction, PostgreSQLConnectionWrapper connection) {
  return connection
      .mappedResultsQuery(sql.sql,
          substitutionValues: sql.parametersByPlaceholder)
      .resolveMapped((results) {
    var count = results
        .map((e) {
          var tableResults = e[table] ?? e[''];
          var count = tableResults?['count'] ?? 0;
          return count is int ? count : int.tryParse(count.toString().trim());
        })
        .whereType<int>()
        .first;
    return count;
  });
}