query library

A typed query builder for SQL Server, on top of the mssql_native driver.

Compilation is separate from execution: MssqlQuery.compile returns an MssqlStatement (sql and parameters). Run both together: session.queryRows(stmt.sql, parameters: stmt.parameters) or db.query(selectQuery). Passing only .sql drops the parameter map.

Query construction and compile() raise Dart runtime errors (missing ORDER BY on a page, eq(null), empty inList). They are not analyzer type errors. Generated column methods such as whereStatus are ordinary Dart methods; that is what turns a class of mistakes into compile-time errors.

Classes

MssqlAggregate
An aggregate expression, optionally evaluated over a window.
MssqlAliased
An expression given a result alias, as in SELECT c.Name AS Customer.
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.
MssqlCalendarRange
An index-friendly half-open calendar range.
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.
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.
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(*).
MssqlCte
One named query in a WITH clause.
MssqlCteField
One column a MssqlTypedCte exposes.
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.
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.
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.
MssqlFrameBound
One end of a MssqlWindowFrame.
MssqlFunction
A SQL function or aggregate over other expressions.
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.
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.
MssqlNegation
NOT (…).
MssqlNotBetween
NOT BETWEEN.
MssqlNullCheck
IS NULL / IS NOT NULL.
MssqlNumericExpression
An expression whose SQL type is a number.
MssqlOrder
One term of an ORDER BY.
MssqlParameterAllocator
Names parameters and collects their values while a statement is compiled.
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.
MssqlRaw
A fragment of SQL written by the caller, with the parameters it uses.
MssqlScalarSubquery
A scalar (SELECT ...) usable anywhere an expression is accepted.
MssqlSelectQuery
A SELECT-shaped statement that can be nested while sharing parameters.
MssqlServerNow
A builder-owned server clock expression.
MssqlSetQuery
A chain of UNION / UNION ALL queries with optional outer ordering.
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.
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.
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.
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.

Enums

MssqlAggregateFunction
Aggregate functions emitted by the query builder.
MssqlArithmeticOperator
Supported arithmetic operators.
MssqlCycleHandling
What a hierarchy walk does when the data has a cycle.
MssqlDateBucketUnit
The width unit of a MssqlDateBucket.
MssqlDateDiffUnit
The unit DATEDIFF counts in.
MssqlDatePart
Date or time component used by comparison helpers.
MssqlEmptyIn
What an IN with no values should do.
MssqlFrameUnit
Which rows a window frame counts.
MssqlIntegerAverage
Controls how AVG handles integer operands.
MssqlJoinKind
The join kinds SQL Server supports.
MssqlLikePosition
Where the wildcards go around an escaped search term.
MssqlNulls
Where SQL Server should put NULLs relative to other values.
MssqlOperator
Comparison operators accepted by column predicates.
MssqlServerClock
SQL Server clock functions and their result types.
MssqlTemporalGrain
Calendar boundaries supported by MssqlDateTruncate.
MssqlTypeFamily
Coarse SQL type families used for compatibility checks.
MssqlWindowFunction
Window functions emitted by the query builder.
MssqlWriteScope
How far a write is allowed to reach.

Mixins

MssqlStableExpression
Caches rendered SQL for the duration of one statement.

Extensions

MssqlExpressionOperators on MssqlExpression
The comparison and predicate operators, on any expression.
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.

Functions

and(Iterable<MssqlCondition> conditions) MssqlCondition
Combines conditions with AND.
avg(MssqlExpression operand, {MssqlIntegerAverage? integers, int exactScale = 6}) MssqlAggregate
AVG(x).
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.
existsValue(MssqlSelectQuery query, {bool negated = false}) MssqlExistsValue
EXISTS (SELECT …) as a projectable bit.
max(MssqlExpression operand) MssqlAggregate
min(MssqlExpression operand) MssqlAggregate
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.
scalarSubquery(MssqlSelectQuery query) MssqlScalarSubquery
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.