added date_type_t, time_type_t and timestamp, ensure allocated postgres resources are released, split repository into basic_repository and repository.

This commit is contained in:
2026-01-06 15:43:20 +01:00
parent f07a360da2
commit 0c6b5a0a93
60 changed files with 1132 additions and 1225 deletions
+18 -91
View File
@@ -4,9 +4,6 @@
namespace matador::utils {
namespace detail {
void initialize_by_basic_type(basic_type type, database_type &val);
size_t determine_size(const std::string &val) {
return val.size();
}
@@ -18,25 +15,22 @@ size_t determine_size(const char *val) {
size_t determine_size(const blob &val) {
return val.size();
}
}
value::value(const basic_type data_type, const size_t size)
: size_(size)
, type_(data_type)
{
, type_(data_type) {
initialize_by_basic_type(type_, value_);
}
value::value(value &&x) noexcept
: value_(std::move(x.value_))
, type_(x.type_)
{
: value_(std::move(x.value_))
, type_(x.type_) {
x.value_ = nullptr;
x.type_ = basic_type::Null;
}
value &value::operator=(value &&x) noexcept
{
value &value::operator=(value &&x) noexcept {
value_ = std::move(x.value_);
type_ = x.type_;
x.value_ = nullptr;
@@ -45,13 +39,11 @@ value &value::operator=(value &&x) noexcept
return *this;
}
std::string value::str() const
{
std::string value::str() const {
return as<std::string>().value_or("");
}
size_t value::size() const
{
size_t value::size() const {
return size_;
}
@@ -60,108 +52,43 @@ basic_type value::type() const {
}
void value::type(const basic_type t) {
type_ = t;
detail::initialize_by_basic_type(type_, value_);
type_ = t;
initialize_by_basic_type(type_, value_);
}
bool value::is_integer() const
{
bool value::is_integer() const {
return type_ >= basic_type::Int8 && type_ <= basic_type::UInt64;
}
bool value::is_floating_point() const
{
bool value::is_floating_point() const {
return type_ == basic_type::Float || type_ == basic_type::Double;
}
bool value::is_bool() const
{
bool value::is_bool() const {
return type_ == basic_type::Boolean;
}
bool value::is_string() const
{
bool value::is_string() const {
return type_ == basic_type::Text;
}
bool value::is_varchar() const
{
bool value::is_varchar() const {
return type_ == basic_type::Varchar;
}
bool value::is_date() const
{
bool value::is_date() const {
return type_ == basic_type::Date;
}
bool value::is_time() const
{
bool value::is_time() const {
return type_ == basic_type::Time;
}
bool value::is_blob() const
{
bool value::is_blob() const {
return type_ == basic_type::Blob;
}
bool value::is_null() const
{
bool value::is_null() const {
return type_ == basic_type::Null;
}
namespace detail {
void initialize_by_basic_type(const basic_type type, database_type &val) {
switch (type) {
case basic_type::Int8:
val.emplace<int8_t>();
break;
case basic_type::Int16:
val.emplace<int16_t>();
break;
case basic_type::Int32:
val.emplace<int32_t>();
break;
case basic_type::Int64:
val.emplace<int64_t>();
break;
case basic_type::UInt8:
val.emplace<uint8_t>();
break;
case basic_type::UInt16:
val.emplace<uint16_t>();
break;
case basic_type::UInt32:
val.emplace<uint32_t>();
break;
case basic_type::UInt64:
val.emplace<uint64_t>();
break;
case basic_type::Boolean:
val.emplace<bool>();
break;
case basic_type::Float:
val.emplace<float>();
break;
case basic_type::Double:
val.emplace<double>();
break;
case basic_type::Varchar:
case basic_type::Text:
val.emplace<std::string>();
break;
// case basic_type::type_date:
// val.emplace<date>();
// break;
// case basic_type::type_time:
// val.emplace<time>();
// break;
case basic_type::Blob:
val.emplace<utils::blob>();
break;
default:
val.emplace<nullptr_t>();
}
}
}
}