generateCountSQL method

FutureOr<SQL> generateCountSQL(
  1. Transaction transaction,
  2. String entityName,
  3. String table, {
  4. EntityMatcher? matcher,
  5. Object? parameters,
  6. List? positionalParameters,
  7. Map<String, Object?>? namedParameters,
})

Implementation

FutureOr<SQL> generateCountSQL(
    Transaction transaction, String entityName, String table,
    {EntityMatcher? matcher,
    Object? parameters,
    List? positionalParameters,
    Map<String, Object?>? namedParameters}) {
  var q = dialect.elementQuote;

  if (matcher == null) {
    var sqlQuery = 'SELECT count(*) as ${q}count$q FROM $q$table$q ';
    return SQL(
      sqlQuery,
      positionalParameters ?? (parameters is List ? parameters : null),
      namedParameters ??
          (parameters is Map<String, dynamic> ? parameters : null),
      {},
      mainTable: table,
    );
  } else {
    return _generateSQLFrom(transaction, entityName, table, matcher,
        parameters: parameters,
        positionalParameters: positionalParameters,
        namedParameters: namedParameters,
        sqlBuilder: (String from, EncodingContext context) {
      return 'SELECT count(*) as ${q}count$q $from';
    });
  }
}