queryList<T> method

Future<List<T>> queryList<T>(
  1. String sql, {
  2. List<Object>? arguments,
  3. required T mapper(
    1. Map<String, Object?>
    ),
})

Executes a SQLite query that may return multiple values.

Implementation

Future<List<T>> queryList<T>(
  final String sql, {
  final List<Object>? arguments,
  required final T Function(Map<String, Object?>) mapper,
}) async {
  final rootNode = _parseRootNode(sql);

  if (rootNode is SelectStatement) {
    return _database
        .rawQuery(sql, arguments)
        .then((rows) => rows.map((row) => mapper(row)).toList());
  } else {
    throw StateError(
        'Unsupported query "$sql" for List return type. It should be SELECT, since DELETE, UPDATE, INSERT returns `int` type.');
  }
}