query<T> method

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

Executes a SQLite query that may return a single value.

Implementation

Future<T?> query<T>(
  final String sql, {
  final List<Object>? arguments,
  required final T Function(Map<String, Object?>) mapper,
}) async {
  final rows = await _preformQuery(sql, arguments);

  if (rows.isEmpty) {
    return null;
  } else if (rows.length > 1) {
    throw StateError("Query returned more than one row for '$sql'");
  }

  return mapper(rows.first);
}