MssqlCte.recursive constructor

MssqlCte.recursive(
  1. String name, {
  2. required MssqlSelectQuery anchor,
  3. required MssqlSelectQuery recursive,
  4. required List<String> columns,
})

A recursive expression: the anchor member, then the member that refers back to name.

T-SQL has no RECURSIVE keyword — SQL Server infers it from the self-reference — so this is UNION ALL between the two members, and it exists as its own constructor because the column list is not optional here: the recursive member's names cannot be derived.

Implementation

factory MssqlCte.recursive(
  String name, {
  required MssqlSelectQuery anchor,
  required MssqlSelectQuery recursive,
  required List<String> columns,
}) {
  if (columns.isEmpty) {
    throw ArgumentError.value(
      columns,
      'columns',
      'A recursive expression must name its columns: SQL Server cannot '
          'derive them from a query that refers to itself.',
    );
  }
  return MssqlCte(name, anchor.unionAll(recursive), columns: columns);
}