MssqlObservedSession class
A session that reports every statement to observer.
This wraps the session rather than the ORM because everything goes through the session — queries, the relation loader, generated typed SQL and a hand-built query alike — so one observer sees the lot. A hook further up would miss exactly the statements worth watching: the ones a relation load fans out into.
"Fifty parents cost three queries" cannot be checked from outside; a counter here makes an N+1 measurable.
Only the session's primitives are overridden. Conveniences derived from
query — queryRows, querySingle, execute — reach the observer
through query. MssqlSession.bulkInsert is its own primitive, so it
is overridden here too rather than looking like an INSERT.
final log = MssqlQueryRecorder();
final db = AppDatabase(connection.observedBy(log.record));
await db.orders.include((o) => [o.customer]).get();
print('${log.count} statements, ${log.elapsed.inMilliseconds}ms');
- Available extensions
Constructors
- MssqlObservedSession(MssqlSession inner, MssqlQueryObserver observer, {MssqlObserverOptions observerOptions = const MssqlObserverOptions(), MssqlDiagnosticSink? onObserverError})
-
const
Properties
- config → MssqlConnectionConfig
-
How the underlying connection was configured.
no setter
- currentDatabase → String
-
The database this session is currently in.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- inner → MssqlSession
-
final
- inTransaction → bool
-
Whether commands on this handle run inside an open transaction.
no setter
- observer → MssqlQueryObserver
-
final
- observerOptions → MssqlObserverOptions
-
final
- onObserverError → MssqlDiagnosticSink?
-
Where an observer exception goes instead of the caller's
catch.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bulkInsert(
{required String tableName, required Iterable< Object> rows, Object? columns, MssqlBulkOptions options = const MssqlBulkOptions(), MssqlCancellationToken? cancellationToken, void onProgress(int sentRows)?}) → Future<MssqlBulkResult> -
Copies
rowsintotableNamethrough BCP. -
callProcedure(
String procedure, {Object parameters = const <String, Object?>{}, Set< String> outputParameters = const <String>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes, MssqlProcedureMetadata? declared, MssqlMetadataDriftPolicy driftPolicy = MssqlMetadataDriftPolicy.preferDeclared}) → Future<MssqlExecutionResult> - Calls a stored procedure, binding parameters from its declared metadata.
-
execute(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< int> -
Runs
sqlfor its effect and returns the affected row count.inherited -
invalidateMetadata(
{String? object}) → void - Drops cached procedure and bulk-table metadata.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
observedBy(
MssqlQueryObserver observer, {MssqlObserverOptions options = const MssqlObserverOptions(), MssqlDiagnosticSink? onObserverError}) → MssqlSession -
Available on MssqlSession, provided by the MssqlObservedSessionExtension extension
This session, reporting every statement toobserver. -
ping(
{MssqlCancellationToken? cancellationToken}) → Future< void> - Checks that the session still answers.
-
query(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes, MssqlRetryPolicy? retry}) → Future< MssqlExecutionResult> -
Runs
sqland buffers every result set. -
queryRows(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes, MssqlRetryPolicy? retry}) → Future< List< Map< >String, Object?> > -
The first result set as maps.
inherited
-
queryScalar<
T> (String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< T> -
The first column of the single row, as
T.inherited -
queryScalarOrNull<
T> (String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< T?> -
The first column of the single row, or null when there is no row.
inherited
-
querySingle(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< Map< String, Object?> > -
Exactly one row, as a map. More than one is an error, not a choice.
inherited
-
querySingleOrNull(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< Map< String, Object?> ?> -
At most one row, as a map.
inherited
-
queryTypedRows(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes, MssqlRetryPolicy? retry}) → Future< List< MssqlRow> > -
The first result set as typed rows, keeping each column's SQL type.
inherited
-
queryTypedSingle(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< MssqlRow> -
Exactly one typed row.
inherited
-
queryTypedSingleOrNull(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken}) → Future< MssqlRow?> -
At most one typed row.
inherited
-
stream(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes}) → Stream< MssqlStreamEvent> - Reported when the stream finishes, with the rows it actually yielded.
-
streamBatches(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes}) → Stream< List< Map< >String, Object?> > -
Batches of maps from a single row-producing result set.
inherited
-
streamRows(
String sql, {Object parameters = const <String, Object?>{}, MssqlQueryOptions options = MssqlQueryOptions.defaults, Duration? timeout, MssqlCancellationToken? cancellationToken, int? batchRows, int? maximumRows, int? maximumBytes}) → Stream< MssqlRow> -
Typed rows from a single row-producing result set, as they arrive.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited