methodAddNode
public SelectQuery<T> AddNode(ISqlNode node)
Appends the specified node to the query AST.
- node: ISqlNode
- The node to append to the query.
Returns: A new `SelectQuery<T>` instance containing the appended node.
methodAlias
public SelectQuery<T> Alias(string alias)
Applies an alias to the current query when used as a subquery.
- alias: string
- The alias to apply.
Returns: A new `SelectQuery<T>` instance with the alias applied.
methodAnd
public SelectQuery<T> And(Expression<Func<T, bool>> predicate)
Appends an AND logical condition to the current WHERE clause using a predicate expression.
- predicate: Expression<Func<T, bool>>
- The expression defining the additional filtering condition.
Returns: A new `SelectQuery<T>` instance with the filter applied.
methodAsAvg
public SelectQuery<T> AsAvg(string column, string? alias = null)
Projects an AVG(column) aggregation.
- column: string
- The column name to average.
- alias: string?
- Optional column alias.
Returns: A new `SelectQuery<T>` instance with the average projection applied.
methodAsCount
public SelectQuery<T> AsCount(string alias = "")
Projects a COUNT(*) aggregation.
- alias: string
- The column alias (default: "count").
Returns: A new `SelectQuery<T>` instance with the count projection applied.
methodAsMax
public SelectQuery<T> AsMax(string column, string? alias = null)
Projects a MAX(column) aggregation.
- column: string
- The column name to find the maximum for.
- alias: string?
- Optional column alias.
Returns: A new `SelectQuery<T>` instance with the max projection applied.
methodAsMin
public SelectQuery<T> AsMin(string column, string? alias = null)
Projects a MIN(column) aggregation.
- column: string
- The column name to find the minimum for.
- alias: string?
- Optional column alias.
Returns: A new `SelectQuery<T>` instance with the min projection applied.
methodAsSum
public SelectQuery<T> AsSum(string column, string? alias = null)
Projects a SUM(column) aggregation.
- column: string
- The column name to sum.
- alias: string?
- Optional column alias.
Returns: A new `SelectQuery<T>` instance with the sum projection applied.
methodBuild
public SqlResult Build(ISqlCompiler compiler)
Compiles the abstract syntax tree into an executable SQL string and its parameters.
- compiler: ISqlCompiler
- The SQL compiler specific to the target database provider.
Returns: The compiled SQL result.
methodCTE
public SelectQuery<T> CTE(string name, ISqlQuery query)
Defines a Common Table Expression (CTE) for the query.
- name: string
- The name assigned to the CTE.
- query: ISqlQuery
- The query defining the CTE data set.
Returns: A new `SelectQuery<T>` instance with the CTE applied.
methodCTE
public SelectQuery<T> CTE(string name, ISqlQuery query, MaterializationHint hint)
Defines a Common Table Expression (CTE) for the query with an explicit materialization hint.
- name: string
- The name assigned to the CTE.
- query: ISqlQuery
- The query defining the CTE data set.
- hint: MaterializationHint
- The materialization hint (e.g. MATERIALIZED or NOT MATERIALIZED in PostgreSQL).
Returns: A new `SelectQuery<T>` instance with the CTE applied.
methodCrossApply
public SelectQuery<T> CrossApply(IAstQuery subquery, string alias)
Appends a CROSS APPLY clause (SQL Server) / INNER JOIN LATERAL (PostgreSQL) to the query. CROSS APPLY returns only rows from the outer query that have matching rows in the correlated subquery.
- subquery: IAstQuery
- The correlated subquery to apply.
- alias: string
- The alias for the applied result set.
Returns: A new `SelectQuery<T>` instance with the CROSS APPLY applied.
methodCrossApply<TSub>
public SelectQuery<T> CrossApply<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias) where TSub : class, new()
Appends a CROSS APPLY clause constructed via a fluent subquery factory.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the applied result set.
Returns: A new `SelectQuery<T>` instance with the CROSS APPLY applied.
methodCrossJoin
public SelectQuery<T> CrossJoin(string tableName, string alias)
Appends a CROSS JOIN clause to the query.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodDistinct
public SelectQuery<T> Distinct()
Applies the DISTINCT modifier to the current SELECT projection to eliminate duplicate rows.
Returns: A new `SelectQuery<T>` instance with the DISTINCT modifier applied.
methodExcept
public SelectQuery<T> Except(ISqlQuery query)
Appends an EXCEPT set operation to return rows from the current query that are not present in the specified query.
- query: ISqlQuery
- The query to compare against.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodExceptAll
public SelectQuery<T> ExceptAll(ISqlQuery query)
Appends an EXCEPT ALL set operation to return rows from the current query not present in the specified query, preserving duplicate counts.
- query: ISqlQuery
- The query to compare against.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodFrom
public SelectQuery<T> From(ISqlQuery query, string alias)
Specifies a subquery as the primary data source.
- query: ISqlQuery
- The subquery to execute.
- alias: string
- The alias for the subquery result set.
Returns: A new `SelectQuery<T>` instance with the subquery FROM clause applied.
methodFrom
public SelectQuery<T> From(string tableName, string? alias = null)
Specifies the primary table to query from.
- tableName: string
- The name of the source table.
- alias: string?
- An optional alias for the source table.
Returns: A new `SelectQuery<T>` instance with the FROM clause applied.
methodFullJoin
public SelectQuery<T> FullJoin(string tableName, string alias, string on)
Appends a FULL OUTER JOIN clause to the query.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
- on: string
- The join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodGroupBy
public SelectQuery<T> GroupBy(params string[] columns)
Appends a GROUP BY clause to the query to aggregate results.
- columns: params string[]
- The names of the columns to group by.
Returns: A new `SelectQuery<T>` instance with the grouping applied.
methodGroupByCube
public SelectQuery<T> GroupByCube(params string[] columns)
Appends a GROUP BY CUBE clause to the query for multidimensional aggregations.
- columns: params string[]
- The names of the columns to produce cube cross-tabulations for.
Returns: A new `SelectQuery<T>` instance with the CUBE grouping applied.
methodGroupByRollup
public SelectQuery<T> GroupByRollup(params string[] columns)
Appends a GROUP BY ROLLUP clause to the query for hierarchical subtotal aggregations.
- columns: params string[]
- The names of the columns in the rollup hierarchy.
Returns: A new `SelectQuery<T>` instance with the ROLLUP grouping applied.
methodGroupingSets
public SelectQuery<T> GroupingSets(params IReadOnlyList<string>[] sets)
Appends a GROUP BY GROUPING SETS clause to the query for explicit multi-level aggregations.
- sets: params IReadOnlyList<string>[]
- The explicit column grouping combinations.
Returns: A new `SelectQuery<T>` instance with the GROUPING SETS grouping applied.
methodHaving
public SelectQuery<T> Having(Expression<Func<T, bool>> predicate)
Appends a HAVING clause to filter aggregated results using a predicate expression.
- predicate: Expression<Func<T, bool>>
- The expression defining the aggregation filter.
Returns: A new `SelectQuery<T>` instance with the aggregation filter applied.
methodHaving
public SelectQuery<T> Having(FormattableString condition)
Appends a raw SQL HAVING clause to filter aggregated results.
- condition: FormattableString
- The formatted string containing the raw filter and its parameters.
Returns: A new `SelectQuery<T>` instance with the aggregation filter applied.
methodInnerJoin
public SelectQuery<T> InnerJoin(string tableName, string alias, string on)
Appends an INNER JOIN clause to the query. This overload is an explicit alias for `Join(string, string, string)` and produces identical SQL. Prefer `Join<TOther>(Expression<Func<T, TOther, bool>>)` for strongly-typed joins using entity expressions.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
- on: string
- The join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodIntersect
public SelectQuery<T> Intersect(ISqlQuery query)
Appends an INTERSECT set operation to return only the rows present in both query results.
- query: ISqlQuery
- The query to intersect with.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodIntersectAll
public SelectQuery<T> IntersectAll(ISqlQuery query)
Appends an INTERSECT ALL set operation to return matching rows from both queries, preserving duplicates.
- query: ISqlQuery
- The query to intersect with.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodJoin
public SelectQuery<T> Join(string tableName, string alias, string on)
Appends an INNER JOIN clause to the query.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
- on: string
- The join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodJoin<TOther>
public SelectQuery<T> Join<TOther>(Expression<Func<T, TOther, bool>> on) where TOther : new()
Appends a strongly-typed INNER JOIN clause to the query based on a predicate.
- on: Expression<Func<T, TOther, bool>>
- The predicate expression defining the join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodJoinSubquery
public SelectQuery<T> JoinSubquery(IAstQuery subquery, string alias, string? on = null)
Appends a JOIN to a subquery (non-lateral, standard INNER JOIN with subquery in parentheses).
- subquery: IAstQuery
- The subquery to join.
- alias: string
- The alias for the derived table.
- on: string?
- The ON condition for the join.
Returns: A new `SelectQuery<T>` instance with the subquery join applied.
methodJoinSubquery<TSub>
public SelectQuery<T> JoinSubquery<TSub>(IAstQuery subquery, string alias, Expression<Func<T, TSub, bool>> on)
Appends a JOIN to a subquery with a typed ON expression.
- subquery: IAstQuery
- The subquery to join.
- alias: string
- The alias for the derived table.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition.
Returns: A new `SelectQuery<T>` instance with the subquery join applied.
methodLateralJoin
public SelectQuery<T> LateralJoin(IAstQuery subquery, string alias, string? on = null)
Appends a LATERAL JOIN clause (INNER JOIN LATERAL) to the query. The subquery is evaluated per-row of the outer query, like a correlated subquery.
- subquery: IAstQuery
- The correlated subquery to laterally join.
- alias: string
- The alias for the lateral result set.
- on: string?
- Optional ON condition string. Usually omitted for LATERAL (use `TRUE` or `null`).
Returns: A new `SelectQuery<T>` instance with the LATERAL JOIN applied.
methodLateralJoin<TSub>
public SelectQuery<T> LateralJoin<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias, Expression<Func<T, TSub, bool>> on) where TSub : class, new()
Appends a LATERAL JOIN clause constructed via a fluent subquery factory with a typed ON expression.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the lateral result set.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition.
Returns: A new `SelectQuery<T>` instance with the LATERAL JOIN applied.
methodLateralJoin<TSub>
public SelectQuery<T> LateralJoin<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias, string? on = null) where TSub : class, new()
Appends a LATERAL JOIN clause constructed via a fluent subquery factory.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the lateral result set.
- on: string?
- Optional raw ON condition string.
Returns: A new `SelectQuery<T>` instance with the LATERAL JOIN applied.
methodLateralJoin<TSub>
public SelectQuery<T> LateralJoin<TSub>(IAstQuery subquery, string alias, Expression<Func<T, TSub, bool>> on)
Appends a LATERAL JOIN clause (INNER JOIN LATERAL) with a typed ON expression.
- subquery: IAstQuery
- The correlated subquery to laterally join.
- alias: string
- The alias for the lateral result set.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition between the outer query and the lateral subquery.
Returns: A new `SelectQuery<T>` instance with the LATERAL JOIN applied.
methodLateralLeftJoin
public SelectQuery<T> LateralLeftJoin(IAstQuery subquery, string alias, string? on = null)
Appends a LEFT LATERAL JOIN clause (LEFT JOIN LATERAL) to the query. Rows from the outer query that have no match in the lateral subquery are preserved.
- subquery: IAstQuery
- The correlated subquery to laterally join.
- alias: string
- The alias for the lateral result set.
- on: string?
- Optional ON condition string.
Returns: A new `SelectQuery<T>` instance with the LEFT LATERAL JOIN applied.
methodLateralLeftJoin<TSub>
public SelectQuery<T> LateralLeftJoin<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias, Expression<Func<T, TSub, bool>> on) where TSub : class, new()
Appends a LEFT LATERAL JOIN clause constructed via a fluent subquery factory with a typed ON expression.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the lateral result set.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition.
Returns: A new `SelectQuery<T>` instance with the LEFT LATERAL JOIN applied.
methodLateralLeftJoin<TSub>
public SelectQuery<T> LateralLeftJoin<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias, string? on = null) where TSub : class, new()
Appends a LEFT LATERAL JOIN clause constructed via a fluent subquery factory.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the lateral result set.
- on: string?
- Optional raw ON condition string.
Returns: A new `SelectQuery<T>` instance with the LEFT LATERAL JOIN applied.
methodLateralLeftJoin<TSub>
public SelectQuery<T> LateralLeftJoin<TSub>(IAstQuery subquery, string alias, Expression<Func<T, TSub, bool>> on)
Appends a LEFT LATERAL JOIN clause (LEFT JOIN LATERAL) with a typed ON expression.
- subquery: IAstQuery
- The correlated subquery to laterally join.
- alias: string
- The alias for the lateral result set.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition between the outer query and the lateral subquery.
Returns: A new `SelectQuery<T>` instance with the LEFT LATERAL JOIN applied.
methodLeftJoin
public SelectQuery<T> LeftJoin(string tableName, string alias, string on)
Appends a LEFT OUTER JOIN clause to the query.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
- on: string
- The join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodLeftJoinSubquery
public SelectQuery<T> LeftJoinSubquery(IAstQuery subquery, string alias, string? on = null)
Appends a LEFT JOIN to a subquery (non-lateral).
- subquery: IAstQuery
- The subquery to join.
- alias: string
- The alias for the derived table.
- on: string?
- The ON condition for the join.
Returns: A new `SelectQuery<T>` instance with the subquery join applied.
methodLeftJoinSubquery<TSub>
public SelectQuery<T> LeftJoinSubquery<TSub>(IAstQuery subquery, string alias, Expression<Func<T, TSub, bool>> on)
Appends a LEFT JOIN to a subquery with a typed ON expression.
- subquery: IAstQuery
- The subquery to join.
- alias: string
- The alias for the derived table.
- on: Expression<Func<T, TSub, bool>>
- The typed predicate expression defining the join condition.
Returns: A new `SelectQuery<T>` instance with the subquery join applied.
methodLimit
public SelectQuery<T> Limit(int limit)
Restricts the maximum number of rows returned by the query.
- limit: int
- The maximum number of rows.
Returns: A new `SelectQuery<T>` instance with the row limit applied.
methodOffset
public SelectQuery<T> Offset(int offset)
Specifies the number of rows to skip before returning results.
- offset: int
- The number of rows to skip.
Returns: A new `SelectQuery<T>` instance with the offset applied.
methodOr
public SelectQuery<T> Or(Expression<Func<T, bool>> predicate)
Appends an OR logical condition to the current WHERE clause using a predicate expression.
- predicate: Expression<Func<T, bool>>
- The expression defining the alternative filtering condition.
Returns: A new `SelectQuery<T>` instance with the filter applied.
methodOrExists
public SelectQuery<T> OrExists(ISqlQuery subquery)
Appends an OR EXISTS (subquery) condition to the query.
- subquery: ISqlQuery
- The subquery to evaluate inside EXISTS.
Returns: A new `SelectQuery<T>` instance with the OR EXISTS filter applied.
methodOrHaving
public SelectQuery<T> OrHaving(Expression<Func<T, bool>> predicate)
Appends an OR logical condition to the current HAVING clause using a predicate expression.
- predicate: Expression<Func<T, bool>>
- The expression defining the alternative aggregation filter.
Returns: A new `SelectQuery<T>` instance with the aggregation filter applied.
methodOrHaving
public SelectQuery<T> OrHaving(FormattableString condition)
Appends a raw SQL OR condition to the current HAVING clause.
- condition: FormattableString
- The formatted string containing the raw alternative filter and its parameters.
Returns: A new `SelectQuery<T>` instance with the aggregation filter applied.
methodOrNotExists
public SelectQuery<T> OrNotExists(ISqlQuery subquery)
Appends an OR NOT EXISTS (subquery) condition to the query.
- subquery: ISqlQuery
- The subquery to evaluate inside NOT EXISTS.
Returns: A new `SelectQuery<T>` instance with the OR NOT EXISTS filter applied.
methodOrderBy
public SelectQuery<T> OrderBy(Expression<Func<T, object>> keySelector)
Appends an ORDER BY clause to sort the results in ascending order.
- keySelector: Expression<Func<T, object>>
- The expression specifying the sorting key.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOrderBy
public SelectQuery<T> OrderBy(Expression<Func<T, object>> keySelector, NullsPosition nulls)
Appends an ORDER BY clause to sort the results in ascending order with explicit NULL placement.
- keySelector: Expression<Func<T, object>>
- The expression specifying the sorting key.
- nulls: NullsPosition
- Controls whether NULLs appear first or last in the ordering.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOrderBy
public SelectQuery<T> OrderBy(FormattableString sql)
Appends a raw SQL ORDER BY clause to sort the results in ascending order.
- sql: FormattableString
- The formatted string containing the raw sorting column or expression.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOrderByDescending
public SelectQuery<T> OrderByDescending(Expression<Func<T, object>> keySelector)
Appends an ORDER BY clause to sort the results in descending order.
- keySelector: Expression<Func<T, object>>
- The expression specifying the sorting key.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOrderByDescending
public SelectQuery<T> OrderByDescending(Expression<Func<T, object>> keySelector, NullsPosition nulls)
Appends an ORDER BY clause to sort the results in descending order with explicit NULL placement.
- keySelector: Expression<Func<T, object>>
- The expression specifying the sorting key.
- nulls: NullsPosition
- Controls whether NULLs appear first or last in the ordering.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOrderByDescending
public SelectQuery<T> OrderByDescending(FormattableString sql)
Appends a raw SQL ORDER BY clause to sort the results in descending order.
- sql: FormattableString
- The formatted string containing the raw sorting column or expression.
Returns: A new `SelectQuery<T>` instance with the sorting rule applied.
methodOuterApply
public SelectQuery<T> OuterApply(IAstQuery subquery, string alias)
Appends an OUTER APPLY clause (SQL Server) / LEFT JOIN LATERAL (PostgreSQL) to the query. OUTER APPLY preserves rows from the outer query even when the correlated subquery returns no rows.
- subquery: IAstQuery
- The correlated subquery to apply.
- alias: string
- The alias for the applied result set.
Returns: A new `SelectQuery<T>` instance with the OUTER APPLY applied.
methodOuterApply<TSub>
public SelectQuery<T> OuterApply<TSub>(Func<SelectQuery<TSub>, IAstQuery> subqueryFactory, string alias) where TSub : class, new()
Appends an OUTER APPLY clause constructed via a fluent subquery factory.
- subqueryFactory: Func<SelectQuery<TSub>, IAstQuery>
- A delegate that configures and returns the correlated subquery.
- alias: string
- The alias for the applied result set.
Returns: A new `SelectQuery<T>` instance with the OUTER APPLY applied.
methodRawJoin
public SelectQuery<T> RawJoin(FormattableString joinSql)
Appends a raw SQL JOIN clause to the query.
- joinSql: FormattableString
- The formatted string containing the raw join command and its parameters.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodRawSelect
public SelectQuery<T> RawSelect(FormattableString sql)
Specifies a raw SQL projection for the SELECT clause.
- sql: FormattableString
- The formatted string containing the raw projection and its parameters.
Returns: A new `SelectQuery<T>` instance with the raw projection applied.
methodRecursiveCTE
public SelectQuery<T> RecursiveCTE(string name, ISqlQuery query)
Defines a recursive Common Table Expression (CTE) for the query.
- name: string
- The name assigned to the CTE.
- query: ISqlQuery
- The query defining the CTE data set.
Returns: A new `SelectQuery<T>` instance with the recursive CTE applied.
methodRecursiveCTE
public SelectQuery<T> RecursiveCTE(string name, ISqlQuery query, MaterializationHint hint)
Defines a recursive Common Table Expression (CTE) for the query with an explicit materialization hint.
- name: string
- The name assigned to the CTE.
- query: ISqlQuery
- The query defining the CTE data set.
- hint: MaterializationHint
- The materialization hint (e.g. MATERIALIZED or NOT MATERIALIZED in PostgreSQL).
Returns: A new `SelectQuery<T>` instance with the recursive CTE applied.
methodRightJoin
public SelectQuery<T> RightJoin(string tableName, string alias, string on)
Appends a RIGHT OUTER JOIN clause to the query.
- tableName: string
- The name of the table to join.
- alias: string
- The alias for the joined table.
- on: string
- The join condition.
Returns: A new `SelectQuery<T>` instance with the join clause applied.
methodSeekAfter
public SelectQuery<T> SeekAfter(params CursorKey[] keys)
Applies a forward composite keyset cursor, seeking rows that come after the specified anchor keys.
- keys: params CursorKey[]
- The anchor key columns and their values from the last row on the current page.
Returns: A new `SelectQuery<T>` with the cursor WHERE predicate applied.
methodSeekBefore
public SelectQuery<T> SeekBefore(params CursorKey[] keys)
Applies a backward composite keyset cursor, seeking rows that come before the specified anchor keys.
- keys: params CursorKey[]
- The anchor key columns and their values from the first row on the current page.
Returns: A new `SelectQuery<T>` with the cursor WHERE predicate applied.
methodSelect
public SelectQuery<T> Select(params EricksonLopez.SqlBuilder.Abstractions.Nodes.WindowFunctionNode[] windows)
Appends one or more window function expressions to the SELECT clause.
- windows: params EricksonLopez.SqlBuilder.Abstractions.Nodes.WindowFunctionNode[]
- One or more `WindowFunctionNode` instances produced by the `Window` factory.
Returns: A new `SelectQuery<T>` instance with the window functions applied.
methodSelect
public SelectQuery<T> Select(ISqlQuery subquery, string alias)
Specifies a scalar subquery projection for the SELECT clause.
- subquery: ISqlQuery
- The subquery that calculates the scalar value.
- alias: string
- The alias name assigned to the scalar column.
Returns: A new `SelectQuery<T>` instance with the scalar subquery applied.
methodSelect
public SelectQuery<T> Select(params string[] columns)
Specifies the columns to project in the SELECT clause.
- columns: params string[]
- The names of the columns to select.
Returns: A new `SelectQuery<T>` instance with the projection applied.
methodSelect<TResult>
public SelectQuery<T> Select<TResult>(Expression<Func<T, TResult>> selector)
Specifies the projection for the SELECT clause using an expression.
- selector: Expression<Func<T, TResult>>
- The expression defining the columns to select.
Returns: A new `SelectQuery<T>` instance with the projection applied.
methodSelectCase
public SelectQuery<T> SelectCase(Abstractions.Nodes.CaseNode caseNode)
Adds a pre-built `Nodes.CaseNode` directly to the SELECT clause.
- caseNode: Abstractions.Nodes.CaseNode
- The prepared case node containing the conditional logic.
Returns: A new `SelectQuery<T>` instance with the CASE column added.
methodSelectCase
public SelectQuery<T> SelectCase(System.Func<Builders.CaseExpressionBuilder, Builders.CaseExpressionBuilder> configure)
Adds a CASE expression column to the SELECT clause using a fluent builder.
- configure: System.Func<Builders.CaseExpressionBuilder, Builders.CaseExpressionBuilder>
- A delegate that configures the `Builders.CaseExpressionBuilder`.
Returns: A new `SelectQuery<T>` instance with the CASE column added.
methodThenBy
public SelectQuery<T> ThenBy(Expression<Func<T, object>> keySelector)
Appends a subsequent sort condition in ascending order.
- keySelector: Expression<Func<T, object>>
- The expression specifying the additional sorting key.
Returns: A new `SelectQuery<T>` instance with the additional sorting rule applied.
methodThenBy
public SelectQuery<T> ThenBy(Expression<Func<T, object>> keySelector, NullsPosition nulls)
Appends a subsequent sort condition in ascending order with explicit NULL placement.
- keySelector: Expression<Func<T, object>>
- The expression specifying the additional sorting key.
- nulls: NullsPosition
- Controls whether NULLs appear first or last.
Returns: A new `SelectQuery<T>` instance with the additional sorting rule applied.
methodThenByDescending
public SelectQuery<T> ThenByDescending(Expression<Func<T, object>> keySelector)
Appends a subsequent sort condition in descending order.
- keySelector: Expression<Func<T, object>>
- The expression specifying the additional sorting key.
Returns: A new `SelectQuery<T>` instance with the additional sorting rule applied.
methodThenByDescending
public SelectQuery<T> ThenByDescending(Expression<Func<T, object>> keySelector, NullsPosition nulls)
Appends a subsequent sort condition in descending order with explicit NULL placement.
- keySelector: Expression<Func<T, object>>
- The expression specifying the additional sorting key.
- nulls: NullsPosition
- Controls whether NULLs appear first or last.
Returns: A new `SelectQuery<T>` instance with the additional sorting rule applied.
methodUnion
public SelectQuery<T> Union(ISqlQuery query)
Appends a UNION set operation to combine results with another query, eliminating duplicates.
- query: ISqlQuery
- The query to union with.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodUnionAll
public SelectQuery<T> UnionAll(ISqlQuery query)
Appends a UNION ALL set operation to combine results with another query, retaining duplicates.
- query: ISqlQuery
- The query to union with.
Returns: A new `SelectQuery<T>` instance with the set operation applied.
methodWhere
public SelectQuery<T> Where(Expression<Func<T, bool>> predicate)
Appends a WHERE clause to the query using a predicate expression.
- predicate: Expression<Func<T, bool>>
- The expression defining the filtering condition.
Returns: A new `SelectQuery<T>` instance with the filter applied.
methodWhere
public SelectQuery<T> Where(FormattableString condition)
Appends a raw SQL WHERE clause to the query.
- condition: FormattableString
- The formatted string containing the raw filter and its parameters.
Returns: A new `SelectQuery<T>` instance with the filter applied.
methodWhereColumns
public SelectQuery<T> WhereColumns(string column1, string operator, string column2)
Appends a comparison between two columns to the WHERE clause.
- column1: string
- The left-hand column name.
- operator: string
- The comparison operator (e.g. "=", "<>", "<", ">", "<=", ">=").
- column2: string
- The right-hand column name.
Returns: A new `SelectQuery<T>` instance.
methodWhereDate
public SelectQuery<T> WhereDate(string column, string operator, object value)
Appends a date comparison condition to the WHERE clause.
- column: string
- The column name containing the date.
- operator: string
- The comparison operator (e.g., "=", ">", "<").
- value: object
- The date value to compare against.
Returns: A new `SelectQuery<T>` instance.
methodWhereDay
public SelectQuery<T> WhereDay(string column, string operator, int day)
Appends a day comparison predicate to the WHERE clause.
- column: string
- The column name containing the date.
- operator: string
- The comparison operator (e.g., "=", ">", "<").
- day: int
- The day integer (1-31) to compare against.
Returns: A new `SelectQuery<T>` instance.
methodWhereExists
public SelectQuery<T> WhereExists(ISqlQuery subquery)
Appends a WHERE EXISTS (subquery) condition to the query.
- subquery: ISqlQuery
- The subquery to evaluate inside EXISTS.
Returns: A new `SelectQuery<T>` instance with the EXISTS filter applied.
methodWhereMonth
public SelectQuery<T> WhereMonth(string column, string operator, int month)
Appends a month comparison predicate to the WHERE clause.
- column: string
- The column name containing the date.
- operator: string
- The comparison operator (e.g., "=", ">", "<").
- month: int
- The month integer (1-12) to compare against.
Returns: A new `SelectQuery<T>` instance.
methodWhereNotExists
public SelectQuery<T> WhereNotExists(ISqlQuery subquery)
Appends a WHERE NOT EXISTS (subquery) condition to the query.
- subquery: ISqlQuery
- The subquery to evaluate inside NOT EXISTS.
Returns: A new `SelectQuery<T>` instance with the NOT EXISTS filter applied.
methodWhereYear
public SelectQuery<T> WhereYear(string column, string operator, int year)
Appends a year comparison predicate to the WHERE clause.
- column: string
- The column name containing the date.
- operator: string
- The comparison operator (e.g., "=", ">", "<").
- year: int
- The year integer to compare against.
Returns: A new `SelectQuery<T>` instance.
methodWindow
public SelectQuery<T> Window(string name, string[]? partitionBy = null, string[]? orderBy = null)
Defines a named window specification for window functions.
- name: string
- The name of the window.
- partitionBy: string[]?
- An optional array of column names to partition the window.
- orderBy: string[]?
- An optional array of column names to order the window.
Returns: A new `SelectQuery<T>` instance with the window specification applied.
methodWindowPage
public SelectQuery<T> WindowPage(int pageNumber, int pageSize, string orderByColumn, bool descending = false)
Applies Window-based pagination (ROW_NUMBER) using the specified column for ordering.
- pageNumber: int
- The one-based page number to retrieve.
- pageSize: int
- The maximum number of items per page. Must be greater than zero.
- orderByColumn: string
- The name of the column to sort by before assigning row numbers.
- descending: bool
- If `true`, sorts the column in descending order; otherwise, ascending.
Returns: A new `SelectQuery<T>` instance with window-based pagination applied.
methodWithTag
public SelectQuery<T> WithTag(string tag)
Creates a new `SelectQuery<T>` with the specified diagnostic tag.
- tag: string
- The diagnostic tag to associate with the query.
Returns: A new query instance containing the applied tag.
propertyNodes
public System.Collections.Immutable.ImmutableArray<ISqlNode> Nodes { get; init; }
Gets the collection of nodes that compose the abstract syntax tree of this query.
propertyTag
public string? Tag { get; init; }
Gets the optional tag associated with this query for diagnostics or interception.