query method

  1. @override
  2. @protected
Future<List<TEntity>> query({
  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<TEntity>> query({
  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,
    );
  }
  final spawnIsolate = useIsolate ?? useIsolateDefault;
  final args = Args<TEntity>(
    t: mType.copyWith(),
    maps: maps,
    isolateArgs: isolateArgs,
    onIsolatePreMap: onIsolatePreMap,
  );
  if (!spawnIsolate) {
    return entitiesFromMap(args).map<TEntity>((e) => e as TEntity).toList();
  }
  final result = await compute(entitiesFromMap, args);
  return result.map<TEntity>((e) => e as TEntity).toList();
}