Database class final
A high-performance SQLite database with reactive queries.
All reads, writes, and reactive re-queries run off the main isolate on persistent worker isolates, keeping your UI thread free.
final db = await Database.open('app.db');
final rows = await db.select('SELECT * FROM users WHERE active = ?', [1]);
await db.execute('INSERT INTO users(name) VALUES (?)', ['Ada']);
db.stream('SELECT * FROM users').listen((users) {
print('${users.length} users');
});
await db.close();
See also:
- Transaction, for multi-statement atomic writes with read visibility
- StreamEngine, for the reactive query lifecycle internals
Properties
-
handle
→ Pointer<
Void> -
The raw native database handle.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- streamEngine → StreamEngine
-
The reactive query engine.
no setter
Methods
-
close(
) → Future< void> - Closes this database, shutting down all worker isolates and releasing native resources.
-
execute(
String sql, [List< Object?> parameters = const []]) → Future<WriteResult> - Executes a write statement and returns the result.
-
executeBatch(
String sql, List< List< paramSets) → Future<Object?> >void> - Executes one SQL statement across many parameter sets in a single transaction.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
select(
String sql, [List< Object?> parameters = const []]) → Future<List< Map< >String, Object?> > - Runs a query and returns all matching rows.
-
selectBytes(
String sql, [List< Object?> parameters = const []]) → Future<Uint8List> - Executes a query and returns the result as JSON-encoded bytes.
-
stream(
String sql, [List< Object?> parameters = const []]) → Stream<List< Map< >String, Object?> > - Creates a reactive query that re-emits results when underlying tables change.
-
toString(
) → String -
A string representation of this object.
inherited
-
transaction<
T> (Future< T> body(Transaction tx)) → Future<T> -
Runs
bodyinside a database transaction.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited