relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct > Class Template Reference

Base SELECT query builder. More...

#include <relx/query/select.hpp>

Public Types

using columns_type = Columns
 
using tables_type = Tables
 
using joins_type = Joins
 
using where_type = Where
 
using group_bys_type = GroupBys
 
using order_bys_type = OrderBys
 
using having_type = HavingCond
 
using limit_type = LimitVal
 
using offset_type = OffsetVal
 

Public Member Functions

 SelectQuery (Columns columns, Tables tables={}, Joins joins={}, Where where=std::nullopt, GroupBys group_bys={}, OrderBys order_bys={}, HavingCond having=std::nullopt, LimitVal limit=std::nullopt, OffsetVal offset=std::nullopt)
 Constructor for the SELECT query builder.
 
std::string to_sql () const
 Generate the SQL for this SELECT query.
 
std::vector< std::string > bind_params () const
 Get the bind parameters for this SELECT query.
 
template<TableType T>
auto from (const T &table) const
 Add a FROM clause to the query.
 
template<TableType... Args>
auto from (const Args &... tables) const
 Add a FROM clause with multiple tables.
 
template<TableType Table, ConditionExpr Condition>
auto join (const Table &table, const Condition &cond, JoinType type=JoinType::Inner) const
 Add a JOIN clause to the query.
 
template<TableType Table, ConditionExpr Condition>
auto left_join (const Table &table, const Condition &cond) const
 Add a LEFT JOIN clause to the query.
 
template<TableType Table, ConditionExpr Condition>
auto right_join (const Table &table, const Condition &cond) const
 Add a RIGHT JOIN clause to the query.
 
template<TableType Table, ConditionExpr Condition>
auto full_join (const Table &table, const Condition &cond) const
 Add a FULL JOIN clause to the query.
 
template<TableType Table>
auto cross_join (const Table &table) const
 Add a CROSS JOIN clause to the query.
 
template<ConditionExpr Condition>
auto where (const Condition &cond) const
 Add a WHERE clause to the query.
 
template<typename... Args>
auto group_by (const Args &... args) const
 Add a GROUP BY clause to the query.
 
template<ConditionExpr Condition>
auto having (const Condition &cond) const
 Add a HAVING clause to the query.
 
template<SqlExpr... Args>
auto order_by (const Args &... args) const
 Add an ORDER BY clause to the query.
 
template<typename T >
requires ColumnType<T>
auto order_by (const T &column) const
 Add an ORDER BY clause to the query.
 
auto limit (int limit) const
 Add a LIMIT clause to the query.
 
auto offset (int offset) const
 Add an OFFSET clause to the query.
 

Detailed Description

template<typename Columns, typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
class relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >

Base SELECT query builder.

Template Parameters
ColumnsTuple of column expressions
TablesTuple of table references
JoinsTuple of join specifications
WhereOptional where condition
GroupBysTuple of group by expressions
OrderBysTuple of order by expressions
HavingCondOptional having condition
LimitValOptional limit value
OffsetValOptional offset value
IsDistinctWhether to use DISTINCT in the query

Definition at line 63 of file select.hpp.

Member Typedef Documentation

◆ columns_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::columns_type = Columns

Definition at line 66 of file select.hpp.

◆ group_bys_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::group_bys_type = GroupBys

Definition at line 70 of file select.hpp.

◆ having_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::having_type = HavingCond

Definition at line 72 of file select.hpp.

◆ joins_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::joins_type = Joins

Definition at line 68 of file select.hpp.

◆ limit_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::limit_type = LimitVal

Definition at line 73 of file select.hpp.

◆ offset_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::offset_type = OffsetVal

Definition at line 74 of file select.hpp.

◆ order_bys_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::order_bys_type = OrderBys

Definition at line 71 of file select.hpp.

◆ tables_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::tables_type = Tables

Definition at line 67 of file select.hpp.

◆ where_type

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
using relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::where_type = Where

Definition at line 69 of file select.hpp.

Constructor & Destructor Documentation

◆ SelectQuery()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::SelectQuery ( Columns  columns,
Tables  tables = {},
Joins  joins = {},
Where  where = std::nullopt,
GroupBys  group_bys = {},
OrderBys  order_bys = {},
HavingCond  having = std::nullopt,
LimitVal  limit = std::nullopt,
OffsetVal  offset = std::nullopt 
)
inlineexplicit

Constructor for the SELECT query builder.

Parameters
columnsThe columns to select
tablesThe tables to select from
joinsThe join specifications
whereThe WHERE condition
group_bysThe GROUP BY expressions
order_bysThe ORDER BY expressions
havingThe HAVING condition
limitThe LIMIT value
offsetThe OFFSET value

Definition at line 86 of file select.hpp.

Member Function Documentation

◆ bind_params()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
std::vector< std::string > relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::bind_params ( ) const
inline

Get the bind parameters for this SELECT query.

Returns
Vector of bind parameters

Definition at line 199 of file select.hpp.

◆ cross_join()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType Table>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::cross_join ( const Table &  table) const
inline

Add a CROSS JOIN clause to the query.

Template Parameters
TableThe table type to join
Parameters
tableThe table to join
Returns
New SelectQuery with the CROSS JOIN clause added

Definition at line 365 of file select.hpp.

◆ from() [1/2]

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType... Args>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::from ( const Args &...  tables) const
inline

Add a FROM clause with multiple tables.

Template Parameters
ArgsThe table types
Parameters
tablesThe tables to select from
Returns
New SelectQuery with the FROM clause added

Definition at line 299 of file select.hpp.

◆ from() [2/2]

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType T>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::from ( const T &  table) const
inline

Add a FROM clause to the query.

Template Parameters
TThe table type
Parameters
tableThe table to select from
Returns
New SelectQuery with the FROM clause added

Definition at line 286 of file select.hpp.

◆ full_join()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType Table, ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::full_join ( const Table &  table,
const Condition &  cond 
) const
inline

Add a FULL JOIN clause to the query.

Template Parameters
TableThe table type to join
ConditionThe join condition type
Parameters
tableThe table to join
condThe join condition
Returns
New SelectQuery with the FULL JOIN clause added

Definition at line 356 of file select.hpp.

◆ group_by()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<typename... Args>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::group_by ( const Args &...  args) const
inline

Add a GROUP BY clause to the query.

Template Parameters
ArgsThe group by expression types
Parameters
argsThe GROUP BY expressions
Returns
New SelectQuery with the GROUP BY clause added

Definition at line 393 of file select.hpp.

◆ having()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::having ( const Condition &  cond) const
inline

Add a HAVING clause to the query.

Template Parameters
ConditionThe condition type
Parameters
condThe HAVING condition
Returns
New SelectQuery with the HAVING clause added

Definition at line 417 of file select.hpp.

◆ join()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType Table, ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::join ( const Table &  table,
const Condition &  cond,
JoinType  type = JoinType::Inner 
) const
inline

Add a JOIN clause to the query.

Template Parameters
TableThe table type to join
ConditionThe join condition type
Parameters
tableThe table to join
condThe join condition
typeThe join type (default: INNER)
Returns
New SelectQuery with the JOIN clause added

Definition at line 315 of file select.hpp.

◆ left_join()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType Table, ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::left_join ( const Table &  table,
const Condition &  cond 
) const
inline

Add a LEFT JOIN clause to the query.

Template Parameters
TableThe table type to join
ConditionThe join condition type
Parameters
tableThe table to join
condThe join condition
Returns
New SelectQuery with the LEFT JOIN clause added

Definition at line 334 of file select.hpp.

◆ limit()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::limit ( int  limit) const
inline

Add a LIMIT clause to the query.

Parameters
limitThe LIMIT value
Returns
New SelectQuery with the LIMIT clause added

Definition at line 460 of file select.hpp.

◆ offset()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::offset ( int  offset) const
inline

Add an OFFSET clause to the query.

Parameters
offsetThe OFFSET value
Returns
New SelectQuery with the OFFSET clause added

Definition at line 472 of file select.hpp.

◆ order_by() [1/2]

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<SqlExpr... Args>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::order_by ( const Args &...  args) const
inline

Add an ORDER BY clause to the query.

Template Parameters
ArgsThe order by expression types
Parameters
argsThe ORDER BY expressions
Returns
New SelectQuery with the ORDER BY clause added

Definition at line 429 of file select.hpp.

◆ order_by() [2/2]

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<typename T >
requires ColumnType<T>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::order_by ( const T &  column) const
inline

Add an ORDER BY clause to the query.

Template Parameters
TThe column type
Parameters
columnThe column to order by
Returns
New SelectQuery with the ORDER BY clause added

Definition at line 444 of file select.hpp.

◆ right_join()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<TableType Table, ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::right_join ( const Table &  table,
const Condition &  cond 
) const
inline

Add a RIGHT JOIN clause to the query.

Template Parameters
TableThe table type to join
ConditionThe join condition type
Parameters
tableThe table to join
condThe join condition
Returns
New SelectQuery with the RIGHT JOIN clause added

Definition at line 345 of file select.hpp.

◆ to_sql()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
std::string relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::to_sql ( ) const
inline

Generate the SQL for this SELECT query.

Returns
The SQL string

Definition at line 97 of file select.hpp.

◆ where()

template<typename Columns , typename Tables = std::tuple<>, typename Joins = std::tuple<>, typename Where = std::nullopt_t, typename GroupBys = std::tuple<>, typename OrderBys = std::tuple<>, typename HavingCond = std::nullopt_t, typename LimitVal = std::nullopt_t, typename OffsetVal = std::nullopt_t, bool IsDistinct = false>
template<ConditionExpr Condition>
auto relx::query::SelectQuery< Columns, Tables, Joins, Where, GroupBys, OrderBys, HavingCond, LimitVal, OffsetVal, IsDistinct >::where ( const Condition &  cond) const
inline

Add a WHERE clause to the query.

Template Parameters
ConditionThe condition type
Parameters
condThe WHERE condition
Returns
New SelectQuery with the WHERE clause added

Definition at line 381 of file select.hpp.


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