select method
Runs a query and returns all matching rows.
final users = await db.select(
'SELECT id, name FROM users WHERE active = ?',
[1],
);
for (final user in users) {
print('${user['id']}: ${user['name']}');
}
The parameters list is bound positionally to ? placeholders in
sql. Returns an empty list if no rows match.
The returned rows are lightweight Row views over a shared result
buffer — accessing row['column'] is a hash lookup, not a map copy.
Use Map<String, Object?>.from(row) if you need a mutable copy.
Runs on a background worker isolate. The main isolate only receives the finished result.
Throws a ResqliteQueryException if the SQL is malformed.
See also:
- selectBytes, for JSON-encoded results without Dart object allocation
- stream, for reactive queries that re-emit on writes
Implementation
Future<List<Map<String, Object?>>> select(
String sql, [
List<Object?> parameters = const [],
]) async {
final transaction = Transaction.current;
if (transaction != null) {
return transaction.select(sql, parameters);
}
_ensureOpen();
final pool = await _readerPool;
// No post-await _ensureOpen re-check: if close() has run while we
// were parked, the pool itself now rejects dispatch with
// ResqliteConnectionException (see ReaderPool._dispatch). That lets
// *in-flight* reads that had already dispatched to a worker finish
// via the pool's drain semantics, while reads still parked on the
// pool future bail out cleanly.
return pool.select(sql, parameters);
}