MssqlAppDatabase<TSelf extends MssqlAppDatabase<TSelf>> class abstract

The entry point for ORM access: holds a session and produces table queries.

Generated code extends this with lazy getters for each table — db.orders, db.customers — that return immutable root queries bound to the right MssqlTableBinding. The base class provides the session lifecycle, transaction support, and the builder-execution seam.

TSelf is the generated class (AppDatabase extends MssqlAppDatabase). The generic is the generated type itself, so transaction hands the callback the same type that has db.orders.

Two construction modes:

  • Borrowedowned is false. close does nothing; the caller closes the resource.
  • Ownedowned is true, typically from generated AppDatabase.open. close closes the connection — or the pool — once.

A pooled database keeps the pool itself, not only its convenience session, because transaction has to hold one lease for the whole callback.

Implementers

Constructors

MssqlAppDatabase(MssqlSession session, {MssqlClock clock = MssqlClock.serverUtc, bool owned = false, MssqlConnectionPool? pool, MssqlChangeHub? changes, MssqlCapabilityCache? capabilities, MssqlQueryObserver? observer, MssqlObserverOptions observerOptions = const MssqlObserverOptions()})

Properties

capabilities MssqlCapabilityCache
Dialect resolution shared by every table query of this database.
final
changes MssqlChangeHub
Committed writes visible to MssqlWatchStrategy.localWrites.
final
clock MssqlClock
The clock timestamp columns use, inherited by transaction contexts.
final
hashCode int
The hash code for this object.
no setterinherited
observer MssqlQueryObserver?
ORM-level observer for compile / mapping / relation-load timings.
final
observerOptions MssqlObserverOptions
final
owned bool
Whether close should close session.
final
pool → MssqlConnectionPool?
The pool behind session, when this database was built with withPool.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
session → MssqlSession
The session every table query reads and writes through.
no setter

Methods

close() Future<void>
Closes the owned resource, if any.
contextFor<T>(MssqlTableBinding<T> binding, {MssqlDialect? dialect}) MssqlQueryContext<T>
A MssqlQueryContext for the current session, for table queries that need one.
execute(MssqlStatement statement, {Duration? timeout, MssqlQueryOptions options = MssqlQueryOptions.defaults}) Future<int>
Executes a built MssqlStatement (INSERT/UPDATE/DELETE) and returns the affected row count.
fork(MssqlSession session) → TSelf
Reconstructs this generated type over session, keeping clock.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(MssqlSelectQuery query, {MssqlDialect? dialect, Duration? timeout, MssqlQueryOptions options = MssqlQueryOptions.defaults}) Future<List<MssqlRow>>
Executes a built MssqlSelectQuery through this database's session.
resolveDialect() Future<MssqlDialect>
What the server is, asked once per capabilities cache.
toString() String
A string representation of this object.
inherited
transaction<R>(Future<R> action(TSelf db)) Future<R>
Runs action inside a transaction, with a new TSelf over the transaction's session.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

borrow(MssqlConnection connection) MssqlUntypedDatabase
Wraps a borrowed MssqlConnection the caller owns.
open(MssqlConnectionConfig config) Future<MssqlUntypedDatabase>
Opens a connection from config and owns it.
withPool(MssqlConnectionPool pool) MssqlUntypedDatabase
Wraps a borrowed MssqlConnectionPool the caller owns.