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

Finalized WITH ... query, usable anywhere a VirtualTable is (subquery, FROM source, etc.) More...

#include <with.hpp>

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

Public Member Functions

 WithQuery (std::string ctes, std::string main, std::string ctes_formatted, std::string main_formatted)
 Wraps already-rendered ctes (name AS (query), ...) and main query text, plus their multi-line formatted counterparts; only reachable via WithBuilder::Main.
 
std::string ToString () const override
 Renders this table value as single-line SQL text. See also ToStringFormatted for a multi-line, indented rendering.
 
std::string ToStringFormatted () const override
 Renders the WITH clause with each CTE in its own indented block, followed by the formatted main query, 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

Finalized WITH ... query, usable anywhere a VirtualTable is (subquery, FROM source, etc.)

See also
https://www.postgresql.org/docs/current/queries-with.html

Member Function Documentation

◆ ToString()

std::string iron_query::WithQuery::ToString ( ) const
overridevirtual

Renders this table value as single-line SQL text. See also ToStringFormatted for a multi-line, indented rendering.

Implements iron_query::VirtualTable.

◆ ToStringFormatted()

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

Renders the WITH clause with each CTE in its own indented block, followed by the formatted main query, e.g.:

WITH
cte AS (
SELECT
a
FROM
foo
)
SELECT
*
FROM
cte

Reimplemented from iron_query::VirtualTable.


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