IronQuery
A SQL-first query builder for C++
Loading...
Searching...
No Matches
Public Member Functions | List of all members
iron_query::SelectExpr Class Referencefinal

Transitional representation for SELECT query. More...

#include <select_expr.hpp>

Inheritance diagram for iron_query::SelectExpr:
Inheritance graph
[legend]
Collaboration diagram for iron_query::SelectExpr:
Collaboration graph
[legend]

Public Member Functions

 SelectExpr (const VirtualTable &tbl)
 Starts a SELECT ... FROM tbl query. tbl may be a table, a join, or anything VirtualTable::As has aliased.
 
SelectExpr Distinct () &&
 Adds DISTINCT to the SELECT list, eliminating duplicate rows.
 
SelectExpr DistinctOn (Expr exp) &&
 Sets DISTINCT ON to a single expression. Mutually exclusive with Distinct.
 
SelectExpr DistinctOn (std::initializer_list< Expr > exps) &&
 Sets DISTINCT ON to a comma-separated list of expressions. Mutually exclusive with Distinct.
 
SelectExpr Select (SelectItem item) &&
 Sets the SELECT list to a single entry.
 
SelectExpr Select (std::initializer_list< SelectItem > items) &&
 Sets the SELECT list to a comma-separated list of entries.
 
SelectExpr Where (Condition exp) &&
 Sets the WHERE clause.
 
SelectExpr OrderBy (OrderByTerm term) &&
 Sets the ORDER BY clause to a single term.
 
SelectExpr OrderBy (std::initializer_list< OrderByTerm > terms) &&
 Sets the ORDER BY clause to a comma-separated list of terms.
 
SelectExpr GroupBy (Expr exp) &&
 Sets the GROUP BY clause to a single expression.
 
SelectExpr GroupBy (std::initializer_list< Expr > exps) &&
 Sets the GROUP BY clause to a comma-separated list of expressions.
 
SelectExpr Having (Condition exp) &&
 Sets the HAVING clause.
 
SelectExpr Limit (int limit) &&
 Sets the LIMIT clause.
 
SelectExpr Offset (int offset) &&
 Sets the OFFSET clause.
 
std::string ToString () const override
 
std::string ToStringFormatted () const override
 Renders the query with each clause on its own line, indented, e.g.:
 
- Public Member Functions inherited from iron_query::VirtualTable
virtual std::string ToStringBracketed () const
 Renders this table value as SQL text, parenthesized so it can be safely embedded as a subquery. Overridden by Table to skip bracketing, since a bare table name never needs it.
 
virtual std::string ToStringAsFromItem () const
 Renders this table value as a FROM item. Distinct from ToStringBracketed because PostgreSQL's table_ref grammar accepts a bare join but parenthesizes one only when an alias follows.
 
Table As (std::string_view name) const
 Aliases this table value as this AS name, usable as a FROM source. name must be a valid (optionally dotted) SQL identifier.
 
 operator Expr () const &&
 Converts this table value into a subquery expression, e.g. for use as a scalar subquery. Only available on rvalues.
 

Detailed Description

Transitional representation for SELECT query.

See also
https://www.postgresql.org/docs/current/sql-select.html

Constructor & Destructor Documentation

◆ SelectExpr()

iron_query::SelectExpr::SelectExpr ( const VirtualTable tbl)

Starts a SELECT ... FROM tbl query. tbl may be a table, a join, or anything VirtualTable::As has aliased.

Exceptions
LogicErrorif tbl is a subquery without an alias.

Member Function Documentation

◆ DistinctOn() [1/2]

SelectExpr iron_query::SelectExpr::DistinctOn ( Expr  exp) &&

Sets DISTINCT ON to a single expression. Mutually exclusive with Distinct.

Exceptions
LogicErrorif DISTINCT ON was already set.

◆ DistinctOn() [2/2]

SelectExpr iron_query::SelectExpr::DistinctOn ( std::initializer_list< Expr exps) &&

Sets DISTINCT ON to a comma-separated list of expressions. Mutually exclusive with Distinct.

Note
Does not check that the leftmost ORDER BY expressions match these, which PostgreSQL requires.
Exceptions
LogicErrorif DISTINCT ON was already set.

◆ GroupBy() [1/2]

SelectExpr iron_query::SelectExpr::GroupBy ( Expr  exp) &&

Sets the GROUP BY clause to a single expression.

Note
Does not check that non-aggregated Select items are covered by the GROUP BY expressions.
Exceptions
LogicErrorif the GROUP BY clause was already set.

◆ GroupBy() [2/2]

SelectExpr iron_query::SelectExpr::GroupBy ( std::initializer_list< Expr exps) &&

Sets the GROUP BY clause to a comma-separated list of expressions.

Note
Does not check that non-aggregated Select items are covered by the GROUP BY expressions.
Exceptions
LogicErrorif the GROUP BY clause was already set.

◆ Having()

SelectExpr iron_query::SelectExpr::Having ( Condition  exp) &&

Sets the HAVING clause.

Note
Does not check that exp references only grouped columns or aggregates.
Exceptions
LogicErrorif the HAVING clause was already set.

◆ Limit()

SelectExpr iron_query::SelectExpr::Limit ( int  limit) &&

Sets the LIMIT clause.

Exceptions
LogicErrorif the LIMIT clause was already set.

◆ Offset()

SelectExpr iron_query::SelectExpr::Offset ( int  offset) &&

Sets the OFFSET clause.

Exceptions
LogicErrorif the OFFSET clause was already set.

◆ OrderBy() [1/2]

SelectExpr iron_query::SelectExpr::OrderBy ( OrderByTerm  term) &&

Sets the ORDER BY clause to a single term.

Exceptions
LogicErrorif the ORDER BY clause was already set.

◆ OrderBy() [2/2]

SelectExpr iron_query::SelectExpr::OrderBy ( std::initializer_list< OrderByTerm terms) &&

Sets the ORDER BY clause to a comma-separated list of terms.

Exceptions
LogicErrorif the ORDER BY clause was already set.

◆ Select() [1/2]

SelectExpr iron_query::SelectExpr::Select ( SelectItem  item) &&

Sets the SELECT list to a single entry.

Exceptions
LogicErrorif the SELECT list was already set.

◆ Select() [2/2]

SelectExpr iron_query::SelectExpr::Select ( std::initializer_list< SelectItem items) &&

Sets the SELECT list to a comma-separated list of entries.

Exceptions
LogicErrorif the SELECT list was already set.

◆ ToString()

std::string iron_query::SelectExpr::ToString ( ) const
overridevirtual
Exceptions
LogicErrorif the SELECT or FROM clause was not set, or if both Distinct and DistinctOn were set.

Implements iron_query::VirtualTable.

◆ ToStringFormatted()

std::string iron_query::SelectExpr::ToStringFormatted ( ) const
overridevirtual

Renders the query with each clause on its own line, indented, e.g.:

SELECT
a,
b
FROM
users
WHERE
a > b
Exceptions
LogicErrorif the SELECT or FROM clause was not set.

Reimplemented from iron_query::VirtualTable.

◆ Where()

SelectExpr iron_query::SelectExpr::Where ( Condition  exp) &&

Sets the WHERE clause.

Exceptions
LogicErrorif the WHERE clause was already set.

The documentation for this class was generated from the following file: