orm library

The repository runtime: what generated table code stands on.

Application code imports the generated AppDatabase barrel (lib/db/generated/generated.dart and database.g.dart), then uses db.orders.whereId(1).get(). This library is what those generated files import. Do not construct MssqlTableBinding or a hand-rolled executor in the getting-started path — there is no MssqlExecutor; the session is MssqlSession from mssql_native.

Query-builder types (MssqlQuery, MssqlHierarchy, MssqlTypedCte, MssqlWindow, MssqlExistsValue, MssqlCalendarRange, inYear, onDate, dateBucket, caseWhen, coalesce) come through query.dart. Generator support types that applications do not need are in generation.dart.

Classes

AbsentField<T>
The column is not named in the statement.
Field<T>
The difference between "the caller did not mention this column" and "the caller set this column to NULL".
MssqlAggregate
An aggregate expression, optionally evaluated over a window.
MssqlAliased
An expression given a result alias, as in SELECT c.Name AS Customer.
MssqlApiVersion
The version of the public API contract that generated code is written against.
MssqlAppDatabase<TSelf extends MssqlAppDatabase<TSelf>>
The entry point for ORM access: holds a session and produces table queries.
MssqlArithmetic
Arithmetic between expressions or a bound value.
MssqlBetween
BETWEEN … AND ….
MssqlBetweenColumns
BETWEEN with expression bounds.
MssqlBinaryColumn
A binary, varbinary or image column.
MssqlBoolColumn
A bit column. Comparable and nothing else.
MssqlBoundColumn
One column, as generated code describes it to the runtime.
MssqlBoundValue
A value bound as a parameter, already encoded for its column's SQL type.
MssqlBulkWriter<TRow>
Batched insert, keyed staging update, and quantity decrement.
MssqlCalendarRange
An index-friendly half-open calendar range.
MssqlCapabilityCache
Shared dialect resolution for one server and one database.
MssqlCase
A searched CASE WHEN … THEN … ELSE … END expression.
MssqlCaseBranch
One WHEN … THEN … of a MssqlCase.
MssqlCast
CAST(expression AS type) while preserving parameter binding.
MssqlChangeHub
Committed table names this AppDatabase family has written.
MssqlClock
Which server clock the runtime uses for timestamp columns.
MssqlCoalesce
Returns the first non-null operand using SQL type precedence.
MssqlColumnBase
A reference to a column, optionally qualified by a table or alias.
MssqlColumnGroup
Applies a predicate to several columns and groups the results.
MssqlColumnRef
A column named as text, with no declared SQL type.
MssqlColumnSchema
MssqlComparison
A binary comparison between an expression and an operand.
MssqlCondition
An expression that produces a boolean, usable in WHERE and HAVING.
MssqlCountAll
COUNT(*), or COUNT_BIG(*).
MssqlCreateManyResult<TRow>
What MssqlBulkWriter.createMany stored, and how well input lines up with what came back.
MssqlCte
One named query in a WITH clause.
MssqlCteField
One column a MssqlTypedCte exposes.
MssqlCursor
A keyset bookmark for MssqlEntityQuery.cursorPage.
MssqlCursorPage<TRow>
One keyset page, with cursors for the neighbouring pages.
MssqlDateBucket
Fixed-width DATE_BUCKET groups from an optional origin.
MssqlDateDiff
Counts unit boundaries between two temporal expressions.
MssqlDatePartComparison
Compares a part of a date column to a value.
MssqlDateTimeColumn
A date, datetime, datetime2 or smalldatetime column.
MssqlDateTimeValueColumn
A datetimeoffset, or a datetime2(7)/time(7) that keeps its 100 ns.
MssqlDateTruncate
Snaps a temporal expression to a calendar boundary.
MssqlDecimalColumn
A decimal, numeric, money or smallmoney column.
MssqlDefault
The DEFAULT keyword, as an assignable operand.
MssqlDefaultValue
The column's declared default, written as the DEFAULT keyword.
MssqlDelete
A single-table DELETE.
MssqlDialect
What the target SQL Server can do, and therefore which SQL a statement is compiled to.
MssqlDistinctCount
COUNT_BIG(DISTINCT expression).
MssqlDoubleColumn
A real/float column.
MssqlEntityQuery<TRow, TFields, S extends MssqlEntityQuery<TRow, TFields, S>>
Abstract base for generated table queries, preserving the concrete query type through every entity-preserving call.
MssqlEnumColumn<T extends Object>
A column whose stored value maps to a Dart enum.
MssqlExistsSubquery
EXISTS (SELECT ...) and its negated form.
MssqlExistsValue
EXISTS (SELECT ...) as a value, for a projection rather than a WHERE.
MssqlExpression
Anything that compiles to a fragment of SQL.
MssqlForeignKeySchema
MssqlFrameBound
One end of a MssqlWindowFrame.
MssqlFunction
A SQL function or aggregate over other expressions.
MssqlGraphInsert<TRow>
One row to insert, plus the relations the caller named for it.
MssqlGraphRelation
One named relation and the graph nodes to write along it.
MssqlGraphWriter<TRow>
Explicit multi-table insert: belongsTo first, parent identity, then children, one transaction, no cascade delete.
MssqlGuidColumn
A uniqueidentifier column.
MssqlHierarchy<K extends Object>
A table whose rows point at other rows of the same table: a category tree, an organisation chart, a bill of materials.
MssqlInList
IN (…) / NOT IN (…).
MssqlInsert
A single-table INSERT.
MssqlInsertSelect
An INSERT ... SELECT statement.
MssqlInSubquery
expression IN (SELECT ...) and its negated form.
MssqlIntColumn
An integer column.
MssqlJoin
MssqlJunction
AND / OR over two or more conditions.
MssqlKeyedPatch
One row of a set-based update: the key that finds it, and the patch.
MssqlLike
LIKE, with the pattern escaped unless the caller asked for raw wildcards.
MssqlLiteral
A value bound as a parameter. Values never reach the SQL text.
MssqlMorph
How a polymorphic relation finds its other side.
MssqlNegation
NOT (…).
MssqlNotBetween
NOT BETWEEN.
MssqlNullCheck
IS NULL / IS NOT NULL.
MssqlNumericExpression
An expression whose SQL type is a number.
MssqlObservedSession
A session that reports every statement to observer.
MssqlObserverOptions
How an observer prints and stores bound parameter values.
MssqlOrder
One term of an ORDER BY.
MssqlOutputClause
An OUTPUT clause on an INSERT, UPDATE or DELETE.
MssqlOutputColumn
One column of an OUTPUT clause.
MssqlOutputTarget
Where an OUTPUT … INTO clause puts its rows.
MssqlPage<TRow>
One page of rows.
MssqlParameterAllocator
Names parameters and collects their values while a statement is compiled.
MssqlPivoted<TChild, TPivot>
A child row plus the pivot row that linked it, for belongsToMany.
MssqlPrimaryKeySchema
MssqlProjectedQuery<R>
A query whose result is R, not an entity row.
MssqlProjection<R>
Column list, aliases, and MssqlRow → R in one descriptor.
MssqlProjectionColumn
One output column of a MssqlProjection.
MssqlQuery
An immutable SELECT. Every method returns a new instance, so a base query can be shared between the page and its count without the two drifting.
MssqlQueryContext<TRow>
Everything a terminal needs to execute a query against one table: the session, the binding, the clock, the dialect and the observer.
MssqlQueryEvent
What one statement did.
MssqlQueryRecorder
Keeps the events, for a request-scoped or development-time report.
MssqlQueryState
Immutable snapshot of every selection a query carries: scope state, user predicates, ordering, and native execution options.
MssqlRaw
A fragment of SQL written by the caller, with the parameters it uses.
MssqlRelation<TParent, TChild>
One relation between two tables, derived from a foreign key.
MssqlRelationAggregate<TParent>
One correlated aggregate to project beside the parent row.
MssqlRelationKey
The key of one row, for grouping loaded children against their parents.
MssqlRelationMutation<TParent, TChild>
Explicit writes against one relation of one parent row.
MssqlRelationThrough
The middle table of a MssqlRelationKind.belongsToMany, MssqlRelationKind.hasManyThrough or MssqlRelationKind.morphToMany.
MssqlRepository<TRow, TKey>
Reads and writes a table described by MssqlTableBinding.
MssqlScalarSubquery
A scalar (SELECT ...) usable anywhere an expression is accepted.
MssqlSchemaCheck
Compares generated bindings against the live database.
MssqlSchemaDifference
One difference between a schema snapshot and the live database.
MssqlSchemaReader
Reads table and view shapes from SQL Server's catalog views.
MssqlSchemaReport
Everything the check found.
MssqlSchemaSnapshot
A database's shape, written to a file, so that generating code does not need a live database.
MssqlScope
A predicate applied to every read of a table, unless it is switched off.
MssqlScopeCompiler
Builds the MssqlCondition list a query carries for a given binding and scope selection, once.
MssqlScopeSelection
Immutable snapshot of which scopes a query carries.
MssqlSelectQuery
A SELECT-shaped statement that can be nested while sharing parameters.
MssqlServerNow
A builder-owned server clock expression.
MssqlServerValue
SQL the server evaluates, such as SYSDATETIME() or [Hits] + @n.
MssqlSetQuery
A chain of UNION / UNION ALL queries with optional outer ordering.
MssqlSoftDelete
How a table records a soft delete.
MssqlSource
A table or view, optionally aliased.
MssqlSourceRef
What a column belongs to, as an identity rather than as a piece of text.
MssqlSourceScope
What each source is called inside one statement.
MssqlSqlType
What an expression is in SQL, as far as anything here can tell.
MssqlStatement
A compiled statement: the SQL text and the values bound to it.
MssqlStringColumn
A character column.
MssqlTableBinding<TRow>
Everything generated code tells the runtime about one table.
MssqlTableSchema
What a table or view is made of, as SQL Server reports it.
MssqlTemporalExpression
An expression whose SQL type is a date, a time or both.
MssqlTextExpression
An expression whose SQL type is text, and which the text predicates accept.
MssqlTimeColumn
A time column, read as an offset from midnight.
MssqlTimestamps
Which columns carry the created and updated stamps.
MssqlTriggerSchema
A trigger, with the timing and events that decide what a write can read back.
MssqlTypeConverter<TDart, TSql>
Converts between a Dart type and what SQL Server stores.
MssqlTypedColumn<T>
A column that knows its Dart type.
MssqlTypedCte
A common table expression whose exposed fields are declared, and whose members are checked against them before any SQL is written.
MssqlTypedExpression
An expression that can report its SQL result type.
MssqlTypedInList
IN (…) over already-bound operands.
MssqlTypedLiteral
A value bound with a column's own SQL type.
MssqlUniqueKeySchema
A unique index or constraint.
MssqlUniqueMatch
A unique-key lookup the schema actually guarantees.
MssqlUntypedDatabase
A database with no generated table getters, for query-builder-only use.
MssqlUpdate
A single-table UPDATE.
MssqlUpsert
SQL Server upsert without MERGE.
MssqlWindow
The OVER (…) clause: how the rows a window function reads are divided and ordered.
MssqlWindowExpression
A non-aggregate window function such as ROW_NUMBER() or LAG().
MssqlWindowFrame
Defines the ROWS or RANGE visible to a window function.
MssqlWriteAssignments
The columns one write names, and what each of them gets.
MssqlWriteEngine<TRow>
The one place insert, update, delete and upsert are executed.
MssqlWriteOutcome
What a write did, and how well that is known.
MssqlWriteValue
One column's contribution to a write.
ValueField<T>
The column is named and carries value.

Enums

MssqlAffectedRowsSource
Where an affected-row count came from, so a caller can judge it.
MssqlAggregateFunction
Aggregate functions emitted by the query builder.
MssqlArithmeticOperator
Supported arithmetic operators.
MssqlCreateManyStrategy
How MssqlBulkWriter.createMany sends rows.
MssqlCycleHandling
What a hierarchy walk does when the data has a cycle.
MssqlCycleWrite
What to do when a graph contains a write cycle.
MssqlDateBucketUnit
The width unit of a MssqlDateBucket.
MssqlDateDiffUnit
The unit DATEDIFF counts in.
MssqlDatePart
Date or time component used by comparison helpers.
MssqlDifferenceKind
What kind of schema change was found.
MssqlDifferenceSeverity
Whether generated code still works with the change.
MssqlEmptyIn
What an IN with no values should do.
MssqlFrameUnit
Which rows a window frame counts.
MssqlIncludeStrategy
How a to-one relation is fetched.
MssqlInsertStrategy
How a row's key comes back from an insert.
MssqlIntegerAverage
Controls how AVG handles integer operands.
MssqlJoinKind
The join kinds SQL Server supports.
MssqlLikePosition
Where the wildcards go around an escaped search term.
MssqlMorphUnknown
What to do when a morphTo type column names a table the map does not have.
MssqlNulls
Where SQL Server should put NULLs relative to other values.
MssqlOperator
Comparison operators accepted by column predicates.
MssqlOrmQueryKind
The session primitives an observer sees.
MssqlOutputSource
Which pseudo-table an OUTPUT column is read from.
MssqlReadConsistency
How a page and its optional count should see the database.
MssqlRelationKind
The relation shapes, matching the vocabulary Eloquent uses.
MssqlServerClock
SQL Server clock functions and their result types.
MssqlTemporalGrain
Calendar boundaries supported by MssqlDateTruncate.
MssqlTrashed
Whether a soft-deleting repository sees deleted rows.
MssqlTriggerKind
What kind of trigger the target table carries.
MssqlTypeFamily
Coarse SQL type families used for compatibility checks.
MssqlWatchStrategy
How MssqlEntityQuery.watch learns that its rows may have changed.
MssqlWindowFunction
Window functions emitted by the query builder.
MssqlWriteReadback
How a write finds out what it stored.
MssqlWriteScope
How far a write is allowed to reach.

Mixins

MssqlStableExpression
Caches rendered SQL for the duration of one statement.

Extensions

MssqlDateTimeConversion on MssqlDateTimeValue
The driver returns every date and time column as an MssqlDateTimeValue — year through nanosecond, plus an offset in minutes — because SQL Server's types each have their own packed layout and hand-decoding them produces plausible wrong answers rather than errors.
MssqlDeleteExecution on MssqlDelete
MssqlExpressionOperators on MssqlExpression
The comparison and predicate operators, on any expression.
MssqlInsertExecution on MssqlInsert
MssqlInsertSelectExecution on MssqlInsertSelect
MssqlObservedSessionExtension on MssqlSession
MssqlQueryExecution on MssqlQuery
Terminal helpers that also reshape an ordinary query before running it.
MssqlSelectQueryExecution on MssqlSelectQuery
Runs any built select, including a union.
MssqlStatementExecution on MssqlStatement
Runs a built statement.
MssqlSubqueryClauses on MssqlQuery
MssqlSubqueryExpressionOperators on MssqlExpression
MssqlTemporalOperators on MssqlTemporalExpression
The date and time expressions, on expressions whose SQL type is temporal.
MssqlTextOperators on MssqlTextExpression
The text predicates, on expressions whose SQL type is text.
MssqlTypedCteClauses on MssqlQuery
Prefixes a query with a typed expression.
MssqlUpdateExecution on MssqlUpdate
MssqlUpsertExecution on MssqlUpsert

Constants

mssqlTruncatedRelationsKey → const String
Map key MssqlTableBinding.applyRelations uses for truncated names.
relationParameterCeiling → const int
SQL Server accepts 2100 parameters in one statement. 2000 leaves room for whatever else the query binds and keeps the arithmetic obvious.
textOnlySqlTypes → const Set<String>
Types the driver has no dedicated model for, which dbconvert returns as their canonical text.

Functions

and(Iterable<MssqlCondition> conditions) MssqlCondition
Combines conditions with AND.
avg(MssqlExpression operand, {MssqlIntegerAverage? integers, int exactScale = 6}) MssqlAggregate
AVG(x).
batchKeys(List<MssqlRelationKey> keys, int columnsPerKey, {int extraParameters = 0}) List<List<MssqlRelationKey>>
Splits keys into batches that stay under the parameter ceiling.
caseWhen(Iterable<MssqlCaseBranch> branches, {MssqlExpression? otherwise, MssqlColumnType? type}) MssqlExpression
CASE WHEN … THEN … ELSE … END.
coalesce(Iterable<MssqlExpression> operands) MssqlExpression
COALESCE(a, b, …): the first operand that is not null.
Col(String identifier) MssqlColumnRef
A short factory for MssqlColumnRef.
count(MssqlExpression operand, {bool distinct = false}) MssqlAggregate
COUNT(x), or COUNT(DISTINCT x) when distinct.
countAll({bool big = false}) MssqlExpression
COUNT(*), or COUNT_BIG(*) when big.
dateDiff(MssqlDateDiffUnit unit, MssqlTemporalExpression start, MssqlTemporalExpression end) MssqlExpression
DATEDIFF(unit, start, end): the number of unit boundaries between two temporal expressions.
diffSchemas({required List<MssqlTableSchema> expected, required List<MssqlTableSchema> actual}) List<MssqlSchemaDifference>
Compares a schema snapshot against the live database.
duplicateKeyIs(MssqlException error, String expected) bool
Whether error names expected as the colliding key.
duplicateKeyName(String message) String?
Parses the index or constraint name out of a 2601/2627 message.
existsValue(MssqlSelectQuery query, {bool negated = false}) MssqlExistsValue
EXISTS (SELECT …) as a projectable bit.
fingerprintOf(MssqlTableSchema table) String
A stable digest of the parts of a table that generated code depends on.
max(MssqlExpression operand) MssqlAggregate
mergeIncludes<TParent>(List<MssqlRelation<TParent, Object?>> current, List<MssqlRelation<TParent, Object?>> extra, {String path = ''}) List<MssqlRelation<TParent, Object?>>
Merges two include lists by relation name.
min(MssqlExpression operand) MssqlAggregate
mssqlNoteCompileElapsed(MssqlSession session, Duration elapsed) → void
Compile elapsed for the statement that is about to run on session.
mssqlRedactParameters(Object parameters, {bool includeValues = false}) Object
Bound parameters with secrets removed.
mssqlRequireNonNull(Object? value, {required String source, required String column}) Object
Unwraps value or throws MssqlUnexpectedNullException.
mssqlTypeForSqlTypeName(String sqlTypeName) → MssqlType?
The driver's classification of sqlTypeName, or null if nothing here recognises it.
not(MssqlCondition condition) MssqlCondition
Negates condition.
or(Iterable<MssqlCondition> conditions) MssqlCondition
Combines conditions with OR.
query(String identifier, {String? as}) MssqlQuery
Shorthand for MssqlQuery.from: query('dbo.Orders').
raw(String sql, [Map<String, Object?> parameters = const <String, Object?>{}]) MssqlRaw
A raw SQL fragment carrying its own parameters.
relationExistsQuery<TParent, TChild>(MssqlRelation<TParent, TChild> relation, {required MssqlTableBinding<TParent> parent, required MssqlSession session, required MssqlDialect dialect, MssqlExpression? projection}) MssqlQuery
Builds a correlated EXISTS / NOT EXISTS subquery for relation.
relationKeyOf<T>(MssqlTableBinding<T> binding, List<String> columns, Map<String, Object?> values) MssqlRelationKey
Groups rows by columns using each column's codec key, not Dart ==.
relationPredicate(List<String> foreignColumns, List<MssqlRelationKey> keys) MssqlCondition
Builds the predicate that fetches children for one batch of parent keys.
scalarSubquery(MssqlSelectQuery query) MssqlScalarSubquery
sessionIsDoomed(MssqlSession session) bool
Whether session can still run a statement.
sum(MssqlExpression operand) MssqlAggregate
SUM(x), carrying SQL Server's own result type; see MssqlAggregate.sum.
whereAll(Iterable<String> columns, MssqlCondition build(MssqlColumnRef column)) MssqlCondition
True when build holds for every one of columns.
whereAny(Iterable<String> columns, MssqlCondition build(MssqlColumnRef column)) MssqlCondition
True when build holds for any of columns.
whereColumn(String left, MssqlOperator operator, String right) MssqlCondition
Compares two columns using operator.
whereNone(Iterable<String> columns, MssqlCondition build(MssqlColumnRef column)) MssqlCondition
True when build holds for none of columns.

Typedefs

MssqlDiagnosticSink = void Function(Object error, StackTrace stack)
Called when an observer itself throws after a statement succeeded.
MssqlQueryObserver = void Function(MssqlQueryEvent event)
Called once per statement, after it finishes.

Exceptions / Errors

MssqlAffectedRowsException
Raised when a write changed a different number of rows than the caller declared with expectAffected.
MssqlBindingMismatchException
Raised when generated code and the connection disagree about something the generated code was compiled for.
MssqlCapabilityException
Raised when a query asks for something the target server cannot do.
MssqlCardinalityException
Raised when single or singleOrNull saw more than one row.
MssqlConcurrencyException
Raised when a version-guarded update or delete matched no rows.
MssqlCursorMismatchException
Raised when a cursor is applied to a different query than issued it.
MssqlIncludeConflictException
Raised when two include() calls name the same path with different options.
MssqlMissingOutputException
Raised when a procedure did not return an OUTPUT parameter the file named.
MssqlOrmException
The shared supertype, so an application can catch every ORM-reached conclusion in one place without also catching server errors.
MssqlReadbackUnavailableException
Raised when a write cannot report the row it stored.
MssqlRelationNotLoadedException
Raised when a relation getter is read on a row that never loaded it.
MssqlRelationTruncatedException
Raised when a relation loaded fewer rows than exist.
MssqlRowNotFoundException
Raised when a row a caller said must exist does not.
MssqlUnexpectedNullException
Raised when a generated mapper required a value and the row held SQL NULL.
MssqlUnexpectedResultSetException
Raised when a procedure returned a different number of result sets than the generated wrapper declared.
MssqlUniqueConflictException
Raised when getOrCreate finds a soft-deleted row, or a unique collision that is not the key it asked about.
MssqlUnknownEnumValueException
Raised when a mapped enum column held a SQL value the enum does not name.
MssqlUnsafeWriteException
Raised when an update or delete would touch every row without the caller having said so.