SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches
sqt::CustomValueTraits< T > Class Template Reference

Description

template<typename T>
class sqt::CustomValueTraits< T >

The primary template for defining traits for custom value types.

Template Parameters
TThe custom value type for which to define traits.

This primary template is intended to be specialized by users for each custom value type. Specializing this template allows fields or accessors with custom value types to be used in column definitions via the SQT_COLUMN_FIELD or SQT_COLUMN_ACCESSOR macros.

Specializations must satisfy the sqt::BasicValueTraitsType concept. The following example demonstrates how to define a specialization for a custom value type mapped to the BLOB data type:

// The custom value type.
struct BLOB {
std::vector<std::byte> data;
};
// The specialization must be defined within the `sqt` namespace.
namespace sqt {
// The specialization for the BLOB type.
template<>
public:
// This type alias must match the custom value type.
using ValueType = BLOB;
// Specifies the data type to which the custom value type is mapped.
// Indicates whether the custom value type is nullable.
static constexpr bool IsNullable = false;
// Binds the custom value to a statement parameter.
static void BindValue(sqt::Statement& statement, int parameter_index, const BLOB& blob) {
statement.BindParameter(parameter_index, blob.data);
}
// Retrieves the custom value from a statement column.
static BLOB RetrieveValue(const sqt::Statement& statement, int column_index) {
auto blob = statement.GetColumnBLOB(column_index);
BLOB result;
result.data.assign(blob.begin(), blob.end());
return result;
}
};
}
The primary template for defining traits for custom value types.
Definition custom_value_traits.h:72
std::span< const std::byte > GetColumnBLOB(int column_index) const noexcept
Gets a span of bytes from the column at the specified index from the current selected row.
Definition statement.cpp:156
void BindParameter(int parameter_index, int value)
Binds the specified int value to the parameter at the specified index.
Definition statement.cpp:47
Wrapper class for SQLite statement.
Definition statement.h:21
DataType
Represents the type of data for an individual column.
Definition data_type.h:16
@ BLOB
Binary data type.
Definition data_type.h:36
See also
sqt::BasicValueTraitsType
SQT_COLUMN_ACCESSOR
SQT_COLUMN_FIELD