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
-
BETWEENwith expression bounds. - MssqlBinaryColumn
-
A
binary,varbinaryorimagecolumn. - MssqlBoolColumn
-
A
bitcolumn. Comparable and nothing else. - MssqlCalendarRange
- An index-friendly half-open calendar range.
- MssqlCase
-
A searched
CASE WHEN … THEN … ELSE … ENDexpression. - 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
WHEREandHAVING. - MssqlCountAll
-
COUNT(*), orCOUNT_BIG(*). - MssqlCte
-
One named query in a
WITHclause. - MssqlCteField
- One column a MssqlTypedCte exposes.
- MssqlDateBucket
-
Fixed-width
DATE_BUCKETgroups 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,datetime2orsmalldatetimecolumn. - MssqlDateTimeValueColumn
-
A
datetimeoffset, or adatetime2(7)/time(7)that keeps its 100 ns. - MssqlDateTruncate
- Snaps a temporal expression to a calendar boundary.
- MssqlDecimalColumn
-
A
decimal,numeric,moneyorsmallmoneycolumn. - 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/floatcolumn. -
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 aWHERE. - 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
uniqueidentifiercolumn. -
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 ... SELECTstatement. - MssqlInSubquery
-
expression IN (SELECT ...)and its negated form. - MssqlIntColumn
- An integer column.
- MssqlJoin
- MssqlJunction
-
AND/ORover 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 ALLqueries 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
timecolumn, 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()orLAG(). - MssqlWindowFrame
-
Defines the
ROWSorRANGEvisible 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
DATEDIFFcounts in. - MssqlDatePart
- Date or time component used by comparison helpers.
- MssqlEmptyIn
-
What an
INwith no values should do. - MssqlFrameUnit
- Which rows a window frame counts.
- MssqlIntegerAverage
-
Controls how
AVGhandles 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
conditionswithAND. -
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), orCOUNT(DISTINCT x)whendistinct. -
countAll(
{bool big = false}) → MssqlExpression -
COUNT(*), orCOUNT_BIG(*)whenbig. -
dateDiff(
MssqlDateDiffUnit unit, MssqlTemporalExpression start, MssqlTemporalExpression end) → MssqlExpression -
DATEDIFF(unit, start, end): the number ofunitboundaries between two temporal expressions. -
existsValue(
MssqlSelectQuery query, {bool negated = false}) → MssqlExistsValue -
EXISTS (SELECT …)as a projectablebit. -
max(
MssqlExpression operand) → MssqlAggregate -
min(
MssqlExpression operand) → MssqlAggregate -
not(
MssqlCondition condition) → MssqlCondition -
Negates
condition. -
or(
Iterable< MssqlCondition> conditions) → MssqlCondition -
Combines
conditionswithOR. -
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
buildholds for every one ofcolumns. -
whereAny(
Iterable< String> columns, MssqlCondition build(MssqlColumnRef column)) → MssqlCondition -
True when
buildholds for any ofcolumns. -
whereColumn(
String left, MssqlOperator operator, String right) → MssqlCondition -
Compares two columns using
operator. -
whereNone(
Iterable< String> columns, MssqlCondition build(MssqlColumnRef column)) → MssqlCondition -
True when
buildholds for none ofcolumns.