relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::schema::column< TableT, Name, T, Modifiers > Class Template Reference

Represents a column in a database table. More...

#include <relx/schema/column.hpp>

Public Types

using table_type = TableT
 The table type this column belongs to.
 
using value_type = T
 The C++ type of the column.
 

Public Member Functions

std::string sql_definition () const
 Get the SQL definition of this column.
 
std::optional< T > get_default_value () const
 Get the default value if set.
 
template<typename PatternType >
requires std::convertible_to<PatternType, std::string>
auto like (PatternType &&pattern) const
 Create a LIKE condition for this column.
 
auto is_null () const
 Create an IS NULL condition for this column.
 
auto is_not_null () const
 Create an IS NOT NULL condition for this column.
 

Static Public Member Functions

static std::string to_sql_string (const T &value)
 Convert a C++ value to SQL string.
 
static T from_sql_string (const std::string &sql_str)
 Parse a SQL string to C++ value.
 

Static Public Attributes

static constexpr auto name = Name
 The column name.
 
static constexpr auto sql_type = column_traits<T>::sql_type_name
 The SQL type of the column.
 
static constexpr bool nullable = column_traits<T>::nullable
 Flag indicating if the column can be NULL.
 

Detailed Description

template<typename TableT, fixed_string Name, typename T, typename... Modifiers>
class relx::schema::column< TableT, Name, T, Modifiers >

Represents a column in a database table.

Template Parameters
TableTThe table type this column belongs to
NameThe name of the column as a string literal
TThe C++ type of the column
ModifiersAdditional column modifiers (UNIQUE, PRIMARY KEY, etc.)

Definition at line 217 of file column.hpp.

Member Typedef Documentation

◆ table_type

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
using relx::schema::column< TableT, Name, T, Modifiers >::table_type = TableT

The table type this column belongs to.

Definition at line 220 of file column.hpp.

◆ value_type

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
using relx::schema::column< TableT, Name, T, Modifiers >::value_type = T

The C++ type of the column.

Definition at line 223 of file column.hpp.

Member Function Documentation

◆ from_sql_string()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
static T relx::schema::column< TableT, Name, T, Modifiers >::from_sql_string ( const std::string &  sql_str)
inlinestatic

Parse a SQL string to C++ value.

Parameters
sql_strThe SQL string to parse
Returns
The C++ value

Definition at line 261 of file column.hpp.

◆ get_default_value()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
std::optional< T > relx::schema::column< TableT, Name, T, Modifiers >::get_default_value ( ) const
inline

Get the default value if set.

Returns
Optional containing the default value or empty if not set

Definition at line 267 of file column.hpp.

◆ is_not_null()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
auto relx::schema::column< TableT, Name, T, Modifiers >::is_not_null ( ) const

Create an IS NOT NULL condition for this column.

Returns
An IS NOT NULL condition expression

Definition at line 1441 of file operators.hpp.

◆ is_null()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
auto relx::schema::column< TableT, Name, T, Modifiers >::is_null ( ) const

Create an IS NULL condition for this column.

Returns
An IS NULL condition expression

Definition at line 1436 of file operators.hpp.

◆ like()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
requires std::convertible_to<PatternType, std::string>
template<typename PatternType >
requires std::convertible_to<PatternType, std::string>
auto relx::schema::column< TableT, Name, T, Modifiers >::like ( PatternType &&  pattern) const

Create a LIKE condition for this column.

Parameters
patternThe pattern to match against
Returns
A LIKE condition expression

Definition at line 1431 of file operators.hpp.

◆ sql_definition()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
std::string relx::schema::column< TableT, Name, T, Modifiers >::sql_definition ( ) const
inline

Get the SQL definition of this column.

Returns
A string containing the SQL column definition

Definition at line 236 of file column.hpp.

◆ to_sql_string()

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
static std::string relx::schema::column< TableT, Name, T, Modifiers >::to_sql_string ( const T &  value)
inlinestatic

Convert a C++ value to SQL string.

Parameters
valueThe value to convert
Returns
SQL string representation

Definition at line 254 of file column.hpp.

Member Data Documentation

◆ name

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
constexpr auto relx::schema::column< TableT, Name, T, Modifiers >::name = Name
staticconstexpr

The column name.

Definition at line 226 of file column.hpp.

◆ nullable

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
constexpr bool relx::schema::column< TableT, Name, T, Modifiers >::nullable = column_traits<T>::nullable
staticconstexpr

Flag indicating if the column can be NULL.

Definition at line 232 of file column.hpp.

◆ sql_type

template<typename TableT , fixed_string Name, typename T , typename... Modifiers>
constexpr auto relx::schema::column< TableT, Name, T, Modifiers >::sql_type = column_traits<T>::sql_type_name
staticconstexpr

The SQL type of the column.

Definition at line 229 of file column.hpp.


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