openDatabase function

Database openDatabase(
  1. Driver driver, {
  2. DatabaseObserver? observer,
})

Takes ownership of driver and creates an explicit database scope.

Call Database.close to release its resources. The root session may execute independent statements; inside a transaction callback use its supplied session. Nested transactions and manually issued transaction boundaries are rejected. SQLite supports only serializable transactions, including read-only transactions enforced by a scoped query_only setting. PostgreSQL supports every Isolation and read-only transactions. The driver's schema is captured once; typed queries use that fixed schema regardless of temporary objects or later PostgreSQL search_path changes. Invalid driver schemas throw before acquisition; the caller retains ownership of a driver when opening fails.

Every completed SQL operation emits a statement, begin, commit or rollback event. Failed operations append Error to that kind. Observer exceptions are ignored so instrumentation cannot change database outcomes. Events expose SQL text, never bound parameters. Avoid literal secrets in SQL.

Implementation

Database openDatabase(Driver driver, {DatabaseObserver? observer}) =>
    _Database(driver, observer);