IronQuery
A SQL-first query builder for C++
Loading...
Searching...
No Matches
with.hpp
1#pragma once
2
3#include <iron_query/virtual_table.hpp>
4#include <string>
5#include <vector>
6
7namespace iron_query {
8
13class [[nodiscard]] WithQuery final : public VirtualTable {
14public:
18 WithQuery(std::string ctes, std::string main, std::string ctes_formatted,
19 std::string main_formatted);
20
21 std::string ToString() const override;
22
38 std::string ToStringFormatted() const override;
39
40private:
41 std::string ctes_;
42 std::string main_;
43 std::string ctes_formatted_;
44 std::string main_formatted_;
45};
46
50class [[nodiscard]] WithBuilder final {
51public:
59 WithBuilder With(std::string name, const VirtualTable &query) &&;
60
62 WithQuery Main(const VirtualTable &query) &&;
63
64private:
66 WithBuilder(std::string name, const VirtualTable &query);
67
68 std::string ctes_;
69 std::string ctes_formatted_;
70 std::vector<std::string> cte_names_;
71
72 friend WithBuilder With(std::string name, const VirtualTable &query);
73};
74
79WithBuilder With(std::string name, const VirtualTable &query);
80
81} // namespace iron_query
Any table value, including physical table, table result, materialized view, etc.
Definition virtual_table.hpp:14
Transitional representation for a WITH clause being built up.
Definition with.hpp:50
friend WithBuilder With(std::string name, const VirtualTable &query)
Handy fabric for WithBuilder. name must be a valid (optionally dotted) SQL identifier.
WithBuilder With(std::string name, const VirtualTable &query) &&
Adds another CTE: , name AS (query). name must be a valid (optionally dotted) SQL identifier not alre...
WithQuery Main(const VirtualTable &query) &&
Finalizes the WITH clause with the main query that follows it.
Finalized WITH ... query, usable anywhere a VirtualTable is (subquery, FROM source,...
Definition with.hpp:13
std::string ToStringFormatted() const override
Renders the WITH clause with each CTE in its own indented block, followed by the formatted main query...
std::string ToString() const override
Renders this table value as single-line SQL text. See also ToStringFormatted for a multi-line,...
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 formatt...
WithBuilder With(std::string name, const VirtualTable &query)
Handy fabric for WithBuilder. name must be a valid (optionally dotted) SQL identifier.