queryMap method

  1. @override
  2. @protected
Future<List<Map<String, dynamic>>> queryMap({
  1. Filter where(
    1. TMeta t
    )?,
  2. Iterable<ColumnDefinition<IEntity, dynamic>>? columns(
    1. TMeta t
    )?,
  3. List<OrmOrder>? orderBy(
    1. TMeta t
    )?,
  4. int? limit,
  5. int? offset,
  6. bool? useIsolate,
  7. Map<String, dynamic>? isolateArgs,
  8. void onIsolatePreMap(
    1. Map<String, dynamic>? isolateArgs
    )?,
})
inherited

Implementation

@override
@protected
Future<List<Map<String, dynamic>>> queryMap({
  Filter Function(TMeta t)? where,
  Iterable<ColumnDefinition>? Function(TMeta t)? columns,
  List<OrmOrder>? Function(TMeta t)? orderBy,
  int? limit,
  int? offset,
  final bool? useIsolate,
  Map<String, dynamic>? isolateArgs,
  void Function(Map<String, dynamic>? isolateArgs)? onIsolatePreMap,
}) async {
  List<Map<String, dynamic>> maps;
  final db = await dbContext.database;
  final cols1 = columns?.call(t);
  if (cols1 == null) {
    throw ArgumentError('no columns supplied');
  }
  List<String> cols = [];
  for (var element in cols1) {
    cols.add(element.name);
  }
  if (cols.isEmpty) {
    throw ArgumentError('no columns supplied');
  }
  String? orderByFilter = orderBy
      ?.call(t)
      ?.map((e) =>
          '${e.column.name} ${e.direction == OrderDirection.desc ? ' DESC' : ''}')
      .join(',');

  if (where == null) {
    maps = await db.query(
      t.tableName,
      columns: cols,
      orderBy: orderByFilter,
      limit: limit,
      offset: offset,
    );
  } else {
    final formattedQuery = await whereString(where, useIsolate);
    maps = await db.query(
      t.tableName,
      columns: cols,
      where: formattedQuery.filter,
      whereArgs: formattedQuery.whereArgs,
      orderBy: orderByFilter,
      limit: limit,
      offset: offset,
    );
  }
  return maps;
}