Lightweight 0.20260303.0
Loading...
Searching...
No Matches
Lightweight::SqlVariant Struct Reference

Represents a value that can be any of the supported SQL data types. More...

#include <SqlVariant.hpp>

Public Types

using InnerType = std::variant< SqlNullType, SqlGuid, bool, int8_t, short, unsigned short, int, unsigned int, long long, unsigned long long, float, double, std::string, std::string_view, std::u16string, std::u16string_view, SqlText, SqlDate, SqlTime, SqlDateTime >
 The inner type of the variant.
 

Public Member Functions

 SqlVariant ()=default
 Default construct a new SqlVariant.
 
 SqlVariant (SqlVariant const &)=default
 Copy construct a new SqlVariant from another.
 
 SqlVariant (SqlVariant &&) noexcept=default
 Move construct a new SqlVariant from another.
 
SqlVariantoperator= (SqlVariant const &)=default
 Copy assign a new SqlVariant from another.
 
SqlVariantoperator= (SqlVariant &&) noexcept=default
 Move assign a new SqlVariant from another.
 
 ~SqlVariant ()=default
 Destructor for SqlVariant.
 
LIGHTWEIGHT_FORCE_INLINE SqlVariant (InnerType const &other)
 Copy constructor of a SqlVariant from one of the supported types.
 
LIGHTWEIGHT_FORCE_INLINE SqlVariant (InnerType &&other) noexcept
 Move constructor of a SqlVariant from one of the supported types.
 
template<std::size_t N, typename T = char, SqlFixedStringMode Mode>
constexpr LIGHTWEIGHT_FORCE_INLINE SqlVariant (SqlFixedString< N, T, Mode > const &other)
 Construct a new SqlVariant from a SqlFixedString.
 
template<std::size_t TextSize>
constexpr LIGHTWEIGHT_FORCE_INLINE SqlVariant (char const (&text)[TextSize])
 Copy constructor of a SqlVariant from a char array.
 
template<std::size_t TextSize>
constexpr LIGHTWEIGHT_FORCE_INLINE SqlVariant (char16_t const (&text)[TextSize])
 Copy constructor of a SqlVariant from a char16_t array.
 
template<typename T >
LIGHTWEIGHT_FORCE_INLINE SqlVariant (std::optional< T > const &other)
 Copy constructor of a SqlVariant from an optional of one of the supported types.
 
LIGHTWEIGHT_FORCE_INLINE SqlVariantoperator= (InnerType const &other)
 Assignment operator of a SqlVariant from one of the supported types.
 
LIGHTWEIGHT_FORCE_INLINE SqlVariantoperator= (InnerType &&other) noexcept
 Assignment operator of a SqlVariant from one of the supported types.
 
template<detail::HasSqlViewHelper StringViewLike>
LIGHTWEIGHT_FORCE_INLINE SqlVariant (StringViewLike const *newValue)
 Construct from an string-like object that implements an SqlViewHelper<>.
 
template<detail::HasSqlViewHelper StringViewLike>
LIGHTWEIGHT_FORCE_INLINE SqlVariantoperator= (StringViewLike const *newValue) noexcept
 Assign from an string-like object that implements an SqlViewHelper<>.
 
LIGHTWEIGHT_FORCE_INLINE bool IsNull () const noexcept
 Check if the value is NULL.
 
template<typename T >
LIGHTWEIGHT_FORCE_INLINE bool Is () const noexcept
 Check if the value is of the specified type.
 
template<typename T >
LIGHTWEIGHT_FORCE_INLINE decltype(auto) Get () noexcept
 Retrieve the value as the specified type.
 
template<typename T >
LIGHTWEIGHT_FORCE_INLINE T ValueOr (T &&defaultValue) const noexcept
 Retrieve the value as the specified type, or return the default value if the value is NULL.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< bool > TryGetBool () const noexcept
 Retrieve the bool from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< int8_t > TryGetInt8 () const noexcept
 Retrieve the int8_t from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< short > TryGetShort () const noexcept
 Retrieve the unsigned short from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned short > TryGetUShort () const noexcept
 Retrieve the unsigned short from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< int > TryGetInt () const noexcept
 Retrieve the int from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned int > TryGetUInt () const noexcept
 Retrieve the unsigned int from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< long long > TryGetLongLong () const noexcept
 Retrieve the long long from the variant or std::nullopt.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned long long > TryGetULongLong () const noexcept
 Retrieve the unsigned long long from the variant or std::nullopt.
 
std::optional< std::string_view > TryGetStringView () const noexcept
 function to get string_view from SqlVariant or std::nullopt
 
std::optional< std::u16string_view > TryGetUtf16StringView () const noexcept
 Retrieves a UTF-16 string view from the variant, or std::nullopt if not available.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDateTryGetDate () const
 function to get SqlDate from SqlVariant or std::nullopt
 
bool operator== (SqlVariant const &other) const noexcept
 Equality comparison operator.
 
bool operator!= (SqlVariant const &other) const noexcept
 Inequality comparison operator.
 
LIGHTWEIGHT_FORCE_INLINE std::optional< SqlTimeTryGetTime () const
 function to get SqlTime from SqlVariant or std::nullopt
 
LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDateTimeTryGetDateTime () const
 function to get SqlDateTime from SqlVariant or std::nullopt
 
LIGHTWEIGHT_FORCE_INLINE std::optional< SqlGuidTryGetGuid () const
 Retrieve the GUID from the variant or std::nullopt if the value is NULL.
 
LIGHTWEIGHT_API std::string ToString () const
 Create string representation of the variant. Can be used for debug purposes.
 

Public Attributes

InnerType value
 The variant value.
 

Detailed Description

Represents a value that can be any of the supported SQL data types.

Use this class with care. Always prefer native types when possible, in order to avoid any unnecessary overhead.

Definition at line 44 of file SqlVariant.hpp.

Member Typedef Documentation

◆ InnerType

using Lightweight::SqlVariant::InnerType = std::variant<SqlNullType, SqlGuid, bool, int8_t, short, unsigned short, int, unsigned int, long long, unsigned long long, float, double, std::string, std::string_view, std::u16string, std::u16string_view, SqlText, SqlDate, SqlTime, SqlDateTime>

The inner type of the variant.

This type is a variant of all the supported SQL data types.

Definition at line 49 of file SqlVariant.hpp.

Constructor & Destructor Documentation

◆ SqlVariant() [1/7]

LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( InnerType const &  other)
inline

Copy constructor of a SqlVariant from one of the supported types.

Definition at line 87 of file SqlVariant.hpp.

◆ SqlVariant() [2/7]

LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( InnerType &&  other)
inlinenoexcept

Move constructor of a SqlVariant from one of the supported types.

Definition at line 93 of file SqlVariant.hpp.

◆ SqlVariant() [3/7]

template<std::size_t N, typename T = char, SqlFixedStringMode Mode>
constexpr LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( SqlFixedString< N, T, Mode > const &  other)
inlineconstexpr

Construct a new SqlVariant from a SqlFixedString.

Definition at line 100 of file SqlVariant.hpp.

◆ SqlVariant() [4/7]

template<std::size_t TextSize>
constexpr LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( char const (&)  text[TextSize])
inlineconstexpr

Copy constructor of a SqlVariant from a char array.

Definition at line 107 of file SqlVariant.hpp.

◆ SqlVariant() [5/7]

template<std::size_t TextSize>
constexpr LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( char16_t const (&)  text[TextSize])
inlineconstexpr

Copy constructor of a SqlVariant from a char16_t array.

Definition at line 114 of file SqlVariant.hpp.

◆ SqlVariant() [6/7]

template<typename T >
LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( std::optional< T > const &  other)
inline

Copy constructor of a SqlVariant from an optional of one of the supported types.

Definition at line 121 of file SqlVariant.hpp.

◆ SqlVariant() [7/7]

template<detail::HasSqlViewHelper StringViewLike>
LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlVariant::SqlVariant ( StringViewLike const *  newValue)
inlineexplicit

Construct from an string-like object that implements an SqlViewHelper<>.

Definition at line 142 of file SqlVariant.hpp.

Member Function Documentation

◆ operator=() [1/3]

LIGHTWEIGHT_FORCE_INLINE SqlVariant & Lightweight::SqlVariant::operator= ( InnerType const &  other)
inline

Assignment operator of a SqlVariant from one of the supported types.

Definition at line 127 of file SqlVariant.hpp.

References value.

◆ operator=() [2/3]

LIGHTWEIGHT_FORCE_INLINE SqlVariant & Lightweight::SqlVariant::operator= ( InnerType &&  other)
inlinenoexcept

Assignment operator of a SqlVariant from one of the supported types.

Definition at line 134 of file SqlVariant.hpp.

References value.

◆ operator=() [3/3]

template<detail::HasSqlViewHelper StringViewLike>
LIGHTWEIGHT_FORCE_INLINE SqlVariant & Lightweight::SqlVariant::operator= ( StringViewLike const *  newValue)
inlinenoexcept

Assign from an string-like object that implements an SqlViewHelper<>.

Definition at line 149 of file SqlVariant.hpp.

References value.

◆ IsNull()

LIGHTWEIGHT_FORCE_INLINE bool Lightweight::SqlVariant::IsNull ( ) const
inlinenoexcept

Check if the value is NULL.

Definition at line 156 of file SqlVariant.hpp.

References value.

Referenced by Get(), TryGetDate(), TryGetDateTime(), TryGetGuid(), TryGetStringView(), TryGetTime(), TryGetUtf16StringView(), and ValueOr().

◆ Is()

template<typename T >
LIGHTWEIGHT_FORCE_INLINE bool Lightweight::SqlVariant::Is ( ) const
inlinenoexcept

Check if the value is of the specified type.

Definition at line 163 of file SqlVariant.hpp.

References value.

◆ Get()

template<typename T >
LIGHTWEIGHT_FORCE_INLINE decltype(auto) Lightweight::SqlVariant::Get ( )
inlinenoexcept

Retrieve the value as the specified type.

Definition at line 170 of file SqlVariant.hpp.

References IsNull(), and value.

◆ ValueOr()

template<typename T >
LIGHTWEIGHT_FORCE_INLINE T Lightweight::SqlVariant::ValueOr ( T &&  defaultValue) const
inlinenoexcept

Retrieve the value as the specified type, or return the default value if the value is NULL.

Definition at line 185 of file SqlVariant.hpp.

References IsNull(), and value.

◆ TryGetBool()

LIGHTWEIGHT_FORCE_INLINE std::optional< bool > Lightweight::SqlVariant::TryGetBool ( ) const
inlinenoexcept

Retrieve the bool from the variant or std::nullopt.

Definition at line 198 of file SqlVariant.hpp.

◆ TryGetInt8()

LIGHTWEIGHT_FORCE_INLINE std::optional< int8_t > Lightweight::SqlVariant::TryGetInt8 ( ) const
inlinenoexcept

Retrieve the int8_t from the variant or std::nullopt.

Definition at line 200 of file SqlVariant.hpp.

◆ TryGetShort()

LIGHTWEIGHT_FORCE_INLINE std::optional< short > Lightweight::SqlVariant::TryGetShort ( ) const
inlinenoexcept

Retrieve the unsigned short from the variant or std::nullopt.

Definition at line 202 of file SqlVariant.hpp.

◆ TryGetUShort()

LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned short > Lightweight::SqlVariant::TryGetUShort ( ) const
inlinenoexcept

Retrieve the unsigned short from the variant or std::nullopt.

Definition at line 204 of file SqlVariant.hpp.

◆ TryGetInt()

LIGHTWEIGHT_FORCE_INLINE std::optional< int > Lightweight::SqlVariant::TryGetInt ( ) const
inlinenoexcept

Retrieve the int from the variant or std::nullopt.

Definition at line 206 of file SqlVariant.hpp.

◆ TryGetUInt()

LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned int > Lightweight::SqlVariant::TryGetUInt ( ) const
inlinenoexcept

Retrieve the unsigned int from the variant or std::nullopt.

Definition at line 208 of file SqlVariant.hpp.

◆ TryGetLongLong()

LIGHTWEIGHT_FORCE_INLINE std::optional< long long > Lightweight::SqlVariant::TryGetLongLong ( ) const
inlinenoexcept

Retrieve the long long from the variant or std::nullopt.

Definition at line 210 of file SqlVariant.hpp.

◆ TryGetULongLong()

LIGHTWEIGHT_FORCE_INLINE std::optional< unsigned long long > Lightweight::SqlVariant::TryGetULongLong ( ) const
inlinenoexcept

Retrieve the unsigned long long from the variant or std::nullopt.

Definition at line 212 of file SqlVariant.hpp.

◆ TryGetStringView()

std::optional< std::string_view > Lightweight::SqlVariant::TryGetStringView ( ) const
inlinenoexcept

function to get string_view from SqlVariant or std::nullopt

Definition at line 233 of file SqlVariant.hpp.

References IsNull(), and value.

◆ TryGetUtf16StringView()

std::optional< std::u16string_view > Lightweight::SqlVariant::TryGetUtf16StringView ( ) const
inlinenoexcept

Retrieves a UTF-16 string view from the variant, or std::nullopt if not available.

Definition at line 249 of file SqlVariant.hpp.

References IsNull(), and value.

◆ TryGetDate()

LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDate > Lightweight::SqlVariant::TryGetDate ( ) const
inline

function to get SqlDate from SqlVariant or std::nullopt

Definition at line 264 of file SqlVariant.hpp.

References IsNull(), and value.

◆ operator==()

bool Lightweight::SqlVariant::operator== ( SqlVariant const &  other) const
inlinenoexcept

Equality comparison operator.

Definition at line 283 of file SqlVariant.hpp.

References ToString().

◆ operator!=()

bool Lightweight::SqlVariant::operator!= ( SqlVariant const &  other) const
inlinenoexcept

Inequality comparison operator.

Definition at line 289 of file SqlVariant.hpp.

◆ TryGetTime()

LIGHTWEIGHT_FORCE_INLINE std::optional< SqlTime > Lightweight::SqlVariant::TryGetTime ( ) const
inline

function to get SqlTime from SqlVariant or std::nullopt

Definition at line 295 of file SqlVariant.hpp.

References IsNull(), and value.

◆ TryGetDateTime()

LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDateTime > Lightweight::SqlVariant::TryGetDateTime ( ) const
inline

function to get SqlDateTime from SqlVariant or std::nullopt

Definition at line 315 of file SqlVariant.hpp.

References IsNull(), and value.

◆ TryGetGuid()

LIGHTWEIGHT_FORCE_INLINE std::optional< SqlGuid > Lightweight::SqlVariant::TryGetGuid ( ) const
inline

Retrieve the GUID from the variant or std::nullopt if the value is NULL.

Definition at line 327 of file SqlVariant.hpp.

References IsNull(), and value.

Member Data Documentation

◆ value

InnerType Lightweight::SqlVariant::value

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