Lightweight 0.1.0
Loading...
Searching...
No Matches
BelongsTo< TheReferencedField, ColumnNameOverrideString > Class Template Reference

Represents a one-to-one relationship. More...

#include <BelongsTo.hpp>

Public Types

using ReferencedRecord = MemberClassType< decltype(TheReferencedField)>
 Represents the record type of the other field.
 
using ValueType = typename std::remove_cvref_t< decltype(std::declval< ReferencedRecord >().*ReferencedField)>::ValueType
 Represents the column type of the foreign key, matching the primary key of the other record.
 

Public Member Functions

template<typename... S>
requires std::constructible_from<ValueType, S...>
constexpr BelongsTo (S &&... value) noexcept
 
constexpr BelongsTo (ReferencedRecord const &other) noexcept
 
constexpr BelongsTo (SelfType const &other) noexcept
 
constexpr BelongsTo (SelfType &&other) noexcept
 
BelongsTooperator= (SqlNullType) noexcept
 
BelongsTooperator= (ReferencedRecord &other)
 
BelongsTooperator= (SelfType const &other)
 
LIGHTWEIGHT_FORCE_INLINE constexpr void SetModified (bool value) noexcept
 Marks the field as modified or unmodified.
 
LIGHTWEIGHT_FORCE_INLINE constexpr bool IsModified () const noexcept
 Checks if the field is modified.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ValueType const & Value () const noexcept
 Retrieves the reference to the value of the field.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ValueTypeMutableValue () noexcept
 Retrieves the mutable reference to the value of the field.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecordRecord ()
 Retrieves a record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & Record () const
 Retrieves an immutable reference to the record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr bool IsLoaded () const noexcept
 Checks if the record is loaded into memory.
 
LIGHTWEIGHT_FORCE_INLINE void Unload () noexcept
 Unloads the record from memory.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecordoperator* () noexcept
 Retrieves the record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & operator* () const noexcept
 Retrieves the record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecordoperator-> ()
 Retrieves the record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const * operator-> () const
 Retrieves the record from the relationship.
 
LIGHTWEIGHT_FORCE_INLINE constexpr bool operator! () const noexcept
 Checks if the field value is NULL.
 
LIGHTWEIGHT_FORCE_INLINE constexpr operator bool () const noexcept
 Checks if the field value is not NULL.
 
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecordEmplaceRecord ()
 Emplaces a record into the relationship. This will mark the relationship as loaded.
 
LIGHTWEIGHT_FORCE_INLINE void BindOutputColumn (SQLSMALLINT outputIndex, SqlStatement &stmt)
 
template<auto OtherReferencedField>
std::weak_ordering operator<=> (BelongsTo< OtherReferencedField > const &other) const noexcept
 
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
std::weak_ordering operator<=> (Field< T, IsPrimaryKeyValue > const &other) const noexcept
 
template<auto OtherReferencedField>
bool operator== (BelongsTo< OtherReferencedField > const &other) const noexcept
 
template<auto OtherReferencedField>
bool operator!= (BelongsTo< OtherReferencedField > const &other) const noexcept
 
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
bool operator== (Field< T, IsPrimaryKeyValue > const &other) const noexcept
 
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
bool operator!= (Field< T, IsPrimaryKeyValue > const &other) const noexcept
 
void SetAutoLoader (Loader loader) noexcept
 Used internally to configure on-demand loading of the record.
 

Static Public Attributes

static constexpr auto ReferencedField = TheReferencedField
 The field in the other record that references the current record.
 
static constexpr std::string_view ColumnNameOverride
 If not an empty string, this value will be used as the column name in the database.
 
static constexpr auto IsOptional = true
 
static constexpr auto IsMandatory = !IsOptional
 
static constexpr auto IsPrimaryKey = false
 
static constexpr auto IsAutoIncrementPrimaryKey = false
 

Detailed Description

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
class BelongsTo< TheReferencedField, ColumnNameOverrideString >

Represents a one-to-one relationship.

The TheReferencedField parameter is the field in the other record that references the current record, in the form of &OtherRecord::Field. Other Field must be a primary key.

Template Parameters
TheReferencedFieldThe field in the other record that references the current record.
ColumnNameOverrideStringIf not an empty string, this value will be used as the column name in the database.
struct User {
};
struct Email {
BelongsTo<&User::id, SqlRealName<"the_user_id">> user; // also possible to customize the column name
};
Represents a one-to-one relationship.
Definition BelongsTo.hpp:42
Represents a single column in a table.
Definition Field.hpp:79
Helper class, used to represent a real SQL column names as template arguments.

Definition at line 41 of file BelongsTo.hpp.

Member Typedef Documentation

◆ ReferencedRecord

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
using BelongsTo< TheReferencedField, ColumnNameOverrideString >::ReferencedRecord = MemberClassType<decltype(TheReferencedField)>

Represents the record type of the other field.

Definition at line 58 of file BelongsTo.hpp.

◆ ValueType

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
using BelongsTo< TheReferencedField, ColumnNameOverrideString >::ValueType = typename std::remove_cvref_t<decltype(std::declval<ReferencedRecord>().*ReferencedField)>::ValueType

Represents the column type of the foreign key, matching the primary key of the other record.

Definition at line 64 of file BelongsTo.hpp.

Constructor & Destructor Documentation

◆ BelongsTo() [1/4]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<typename... S>
requires std::constructible_from<ValueType, S...>
constexpr BelongsTo< TheReferencedField, ColumnNameOverrideString >::BelongsTo ( S &&...  value)
inlineconstexprnoexcept

Definition at line 73 of file BelongsTo.hpp.

◆ BelongsTo() [2/4]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr BelongsTo< TheReferencedField, ColumnNameOverrideString >::BelongsTo ( ReferencedRecord const &  other)
inlineconstexprnoexcept

Definition at line 78 of file BelongsTo.hpp.

◆ BelongsTo() [3/4]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr BelongsTo< TheReferencedField, ColumnNameOverrideString >::BelongsTo ( SelfType const &  other)
inlineconstexprnoexcept

Definition at line 85 of file BelongsTo.hpp.

◆ BelongsTo() [4/4]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr BelongsTo< TheReferencedField, ColumnNameOverrideString >::BelongsTo ( SelfType &&  other)
inlineconstexprnoexcept

Definition at line 94 of file BelongsTo.hpp.

Member Function Documentation

◆ operator=() [1/3]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
BelongsTo & BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator= ( SqlNullType  )
inlinenoexcept

Definition at line 104 of file BelongsTo.hpp.

◆ operator=() [2/3]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
BelongsTo & BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator= ( ReferencedRecord other)
inline

Definition at line 115 of file BelongsTo.hpp.

◆ operator=() [3/3]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
BelongsTo & BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator= ( SelfType const &  other)
inline

Definition at line 126 of file BelongsTo.hpp.

◆ SetModified()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr void BelongsTo< TheReferencedField, ColumnNameOverrideString >::SetModified ( bool  value)
inlineconstexprnoexcept

Marks the field as modified or unmodified.

Definition at line 143 of file BelongsTo.hpp.

◆ IsModified()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsModified ( ) const
inlineconstexprnoexcept

Checks if the field is modified.

Definition at line 146 of file BelongsTo.hpp.

◆ Value()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ValueType const & BelongsTo< TheReferencedField, ColumnNameOverrideString >::Value ( ) const
inlineconstexprnoexcept

Retrieves the reference to the value of the field.

Definition at line 149 of file BelongsTo.hpp.

◆ MutableValue()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ValueType & BelongsTo< TheReferencedField, ColumnNameOverrideString >::MutableValue ( )
inlineconstexprnoexcept

Retrieves the mutable reference to the value of the field.

Definition at line 152 of file BelongsTo.hpp.

◆ Record() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & BelongsTo< TheReferencedField, ColumnNameOverrideString >::Record ( )
inlineconstexpr

Retrieves a record from the relationship.

Definition at line 155 of file BelongsTo.hpp.

◆ Record() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & BelongsTo< TheReferencedField, ColumnNameOverrideString >::Record ( ) const
inlineconstexpr

Retrieves an immutable reference to the record from the relationship.

Definition at line 158 of file BelongsTo.hpp.

◆ IsLoaded()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsLoaded ( ) const
inlineconstexprnoexcept

Checks if the record is loaded into memory.

Definition at line 161 of file BelongsTo.hpp.

◆ Unload()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE void BelongsTo< TheReferencedField, ColumnNameOverrideString >::Unload ( )
inlinenoexcept

Unloads the record from memory.

Definition at line 164 of file BelongsTo.hpp.

◆ operator*() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator* ( )
inlineconstexprnoexcept

Retrieves the record from the relationship.

Definition at line 167 of file BelongsTo.hpp.

◆ operator*() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const & BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator* ( ) const
inlineconstexprnoexcept

Retrieves the record from the relationship.

Definition at line 170 of file BelongsTo.hpp.

◆ operator->() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord * BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator-> ( )
inlineconstexpr

Retrieves the record from the relationship.

Definition at line 173 of file BelongsTo.hpp.

◆ operator->() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord const * BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator-> ( ) const
inlineconstexpr

Retrieves the record from the relationship.

Definition at line 176 of file BelongsTo.hpp.

◆ operator!()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator! ( ) const
inlineconstexprnoexcept

Checks if the field value is NULL.

Definition at line 179 of file BelongsTo.hpp.

◆ operator bool()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Checks if the field value is not NULL.

Definition at line 182 of file BelongsTo.hpp.

◆ EmplaceRecord()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE constexpr ReferencedRecord & BelongsTo< TheReferencedField, ColumnNameOverrideString >::EmplaceRecord ( )
inlineconstexpr

Emplaces a record into the relationship. This will mark the relationship as loaded.

Definition at line 187 of file BelongsTo.hpp.

◆ BindOutputColumn()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
LIGHTWEIGHT_FORCE_INLINE void BelongsTo< TheReferencedField, ColumnNameOverrideString >::BindOutputColumn ( SQLSMALLINT  outputIndex,
SqlStatement stmt 
)
inline

Definition at line 194 of file BelongsTo.hpp.

◆ operator<=>() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<auto OtherReferencedField>
std::weak_ordering BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator<=> ( BelongsTo< OtherReferencedField > const &  other) const
inlinenoexcept

Definition at line 200 of file BelongsTo.hpp.

◆ operator<=>() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
std::weak_ordering BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator<=> ( Field< T, IsPrimaryKeyValue > const &  other) const
inlinenoexcept

Definition at line 206 of file BelongsTo.hpp.

◆ operator==() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<auto OtherReferencedField>
bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator== ( BelongsTo< OtherReferencedField > const &  other) const
inlinenoexcept

Definition at line 212 of file BelongsTo.hpp.

◆ operator!=() [1/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<auto OtherReferencedField>
bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator!= ( BelongsTo< OtherReferencedField > const &  other) const
inlinenoexcept

Definition at line 218 of file BelongsTo.hpp.

◆ operator==() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator== ( Field< T, IsPrimaryKeyValue > const &  other) const
inlinenoexcept

Definition at line 224 of file BelongsTo.hpp.

◆ operator!=() [2/2]

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
template<detail::FieldElementType T, PrimaryKey IsPrimaryKeyValue = PrimaryKey::No>
bool BelongsTo< TheReferencedField, ColumnNameOverrideString >::operator!= ( Field< T, IsPrimaryKeyValue > const &  other) const
inlinenoexcept

Definition at line 230 of file BelongsTo.hpp.

◆ SetAutoLoader()

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
void BelongsTo< TheReferencedField, ColumnNameOverrideString >::SetAutoLoader ( Loader  loader)
inlinenoexcept

Used internally to configure on-demand loading of the record.

Definition at line 241 of file BelongsTo.hpp.

Member Data Documentation

◆ ReferencedField

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr auto BelongsTo< TheReferencedField, ColumnNameOverrideString >::ReferencedField = TheReferencedField
staticconstexpr

The field in the other record that references the current record.

Definition at line 47 of file BelongsTo.hpp.

◆ ColumnNameOverride

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr std::string_view BelongsTo< TheReferencedField, ColumnNameOverrideString >::ColumnNameOverride
staticconstexpr
Initial value:
= []() consteval {
if constexpr (!std::same_as<decltype(ColumnNameOverrideString), std::nullopt_t>)
return std::string_view { ColumnNameOverrideString };
else
return std::string_view {};
}()

If not an empty string, this value will be used as the column name in the database.

Definition at line 50 of file BelongsTo.hpp.

◆ IsOptional

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr auto BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsOptional = true
staticconstexpr

Definition at line 66 of file BelongsTo.hpp.

◆ IsMandatory

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr auto BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsMandatory = !IsOptional
staticconstexpr

Definition at line 67 of file BelongsTo.hpp.

◆ IsPrimaryKey

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr auto BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsPrimaryKey = false
staticconstexpr

Definition at line 68 of file BelongsTo.hpp.

◆ IsAutoIncrementPrimaryKey

template<auto TheReferencedField, auto ColumnNameOverrideString = std::nullopt>
constexpr auto BelongsTo< TheReferencedField, ColumnNameOverrideString >::IsAutoIncrementPrimaryKey = false
staticconstexpr

Definition at line 69 of file BelongsTo.hpp.


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