relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns > Class Template Reference

Base UPDATE query builder. More...

#include <relx/query/update.hpp>

Public Types

using table_type = Table
 
using sets_type = Sets
 
using where_type = Where
 
using returning_columns_type = ReturningColumns
 

Public Member Functions

 UpdateQuery (Table table, Sets sets={}, Where where=std::nullopt, ReturningColumns returning_columns={})
 Constructor for the UPDATE query builder.
 
std::string to_sql () const
 Generate the SQL for this UPDATE query.
 
std::vector< std::string > bind_params () const
 Get the bind parameters for this UPDATE query.
 
template<ColumnType Col, SqlExpr Val>
auto set (const Col &column, Val &&val) const
 Add or replace a SET clause assignment.
 
template<ColumnType Col, typename T >
requires (!SqlExpr<T>)
auto set (const Col &column, T &&val) const
 Add or replace a SET clause assignment with a raw value (with type checking)
 
template<ConditionExpr Condition>
auto where (const Condition &cond) const
 Add a WHERE clause to the query.
 
template<ColumnType Col, std::ranges::range Range>
requires std::convertible_to<std::ranges::range_value_t<Range>, std::string>
auto where_in (const Col &column, const Range &values) const
 Set a condition for filtering the rows to update using IN with values.
 
template<typename... Args>
auto returning (const Args &... args) const
 Specify columns to return after update.
 

Detailed Description

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
class relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >

Base UPDATE query builder.

Template Parameters
TableTable to update
SetsTuple of SET clause items
WhereOptional where condition
ReturningColumnsTuple of column expressions to return after update

Definition at line 43 of file update.hpp.

Member Typedef Documentation

◆ returning_columns_type

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
using relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::returning_columns_type = ReturningColumns

Definition at line 89 of file update.hpp.

◆ sets_type

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
using relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::sets_type = Sets

Definition at line 87 of file update.hpp.

◆ table_type

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
using relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::table_type = Table

Definition at line 86 of file update.hpp.

◆ where_type

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
using relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::where_type = Where

Definition at line 88 of file update.hpp.

Constructor & Destructor Documentation

◆ UpdateQuery()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::UpdateQuery ( Table  table,
Sets  sets = {},
Where  where = std::nullopt,
ReturningColumns  returning_columns = {} 
)
inlineexplicit

Constructor for the UPDATE query builder.

Parameters
tableThe table to update
setsThe SET clause items
whereThe WHERE condition
returning_columnsThe columns to return after update

Definition at line 96 of file update.hpp.

Member Function Documentation

◆ bind_params()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
std::vector< std::string > relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::bind_params ( ) const
inline

Get the bind parameters for this UPDATE query.

Returns
Vector of bind parameters

Definition at line 128 of file update.hpp.

◆ returning()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
template<typename... Args>
auto relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::returning ( const Args &...  args) const
inline

Specify columns to return after update.

Template Parameters
ArgsColumn types or SQL expressions
Parameters
argsThe columns or expressions to return
Returns
New UpdateQuery with the RETURNING clause added

Definition at line 223 of file update.hpp.

◆ set() [1/2]

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
template<ColumnType Col, typename T >
requires (!SqlExpr<T>)
auto relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::set ( const Col &  column,
T &&  val 
) const
inline

Add or replace a SET clause assignment with a raw value (with type checking)

Template Parameters
ColThe column type
TThe raw value type
Parameters
columnThe column to set
valThe raw value to set
Returns
New UpdateQuery with the SET clause added

Definition at line 185 of file update.hpp.

◆ set() [2/2]

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
template<ColumnType Col, SqlExpr Val>
auto relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::set ( const Col &  column,
Val &&  val 
) const
inline

Add or replace a SET clause assignment.

Template Parameters
ColThe column type
ValThe value expression type
Parameters
columnThe column to set
valThe value to set
Returns
New UpdateQuery with the SET clause added

Definition at line 159 of file update.hpp.

◆ to_sql()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
std::string relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::to_sql ( ) const
inline

Generate the SQL for this UPDATE query.

Returns
The SQL string

Definition at line 103 of file update.hpp.

◆ where()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
template<ConditionExpr Condition>
auto relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::where ( const Condition &  cond) const
inline

Add a WHERE clause to the query.

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

Definition at line 199 of file update.hpp.

◆ where_in()

template<TableType Table, typename Sets = std::tuple<>, typename Where = std::nullopt_t, typename ReturningColumns = std::tuple<>>
template<ColumnType Col, std::ranges::range Range>
requires std::convertible_to<std::ranges::range_value_t<Range>, std::string>
auto relx::query::UpdateQuery< Table, Sets, Where, ReturningColumns >::where_in ( const Col &  column,
const Range &  values 
) const
inline

Set a condition for filtering the rows to update using IN with values.

Template Parameters
ColThe column type
RangeThe range type for IN values
Parameters
columnThe column to check
valuesThe values to check against
Returns
New UpdateQuery with the IN condition added

Definition at line 212 of file update.hpp.


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