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:
@@ -3,39 +3,36 @@
|
||||
|
||||
#include "matador/utils/types.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
//#include "matador/utils/date.hpp"
|
||||
//#include "matador/utils/time.hpp"
|
||||
|
||||
//#include "matador/utils/placeholder.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
/*
|
||||
* Conversion matrix
|
||||
* from> | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | bool | float | double | string | date | time | blob | placeholder | null
|
||||
* to | | | | | | | | | | | | | | | | |
|
||||
* ------------+------+-------+-------+-------+-------+--------+--------+--------+------+-------+--------+--------+------+------+------+-------------+-----
|
||||
* int8 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* int16 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* int32 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* int64 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* uint8 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* uint16 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* uint32 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* uint64 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | try | N/A | N/A
|
||||
* bool | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | try | N/A | N/A
|
||||
* float | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | try | N/A | N/A
|
||||
* double | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | try | N/A | N/A
|
||||
* string | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A
|
||||
* date | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A | try | ok | ok | N/A | N/A | N/A
|
||||
* time | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A | try | ok | ok | N/A | N/A | N/A
|
||||
* blob | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A
|
||||
* placeholder | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ok | N/A
|
||||
* null | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ok
|
||||
* from> | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | bool | float | double | string | date | time | timestamp | blob | null
|
||||
* to | | | | | | | | | | | | | | | | |
|
||||
* ------------+------+-------+-------+-------+-------+--------+--------+--------+------+-------+--------+--------+------+------+-----------+------+-----
|
||||
* int8 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* int16 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* int32 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* int64 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* uint8 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* uint16 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* uint32 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* uint64 | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | ok | ok | ok | try | N/A
|
||||
* bool | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | ok | try | N/A
|
||||
* float | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | ok | try | N/A
|
||||
* double | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | try | N/A | N/A | ok | try | N/A
|
||||
* string | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A
|
||||
* date | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A | try | ok | ok | ok | N/A | N/A
|
||||
* time | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A | try | ok | ok | ok | N/A | N/A
|
||||
* timestamp | ok | ok | ok | ok | ok | ok | ok | ok | N/A | N/A | N/A | try | ok | ok | ok | N/A | N/A
|
||||
* blob | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | ok | N/A
|
||||
* null | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ok | ok
|
||||
*
|
||||
* from integral to date/time works, value is interpreted as std::chrono::timepoint
|
||||
* from integral to blob works, bytes of integral data will converted to blob
|
||||
@@ -97,7 +94,6 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
|
||||
return ok(std::string(buffer.data(), ptr));
|
||||
}
|
||||
|
||||
// return failure({ec, "couldn't convert value to std::string"});
|
||||
return failure(conversion_error::NotConvertable/*, "couldn't convert value to std::string"}*/);
|
||||
}
|
||||
|
||||
@@ -110,7 +106,6 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
|
||||
return ok(std::string(buffer.data(), ptr));
|
||||
}
|
||||
|
||||
// return failure({ec, "couldn't convert value to std::string"});
|
||||
return failure(conversion_error::NotConvertable/*, "couldn't convert value to std::string"}*/);
|
||||
}
|
||||
|
||||
@@ -257,6 +252,105 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, date_type_t>>* = nullptr) {
|
||||
std::tm result{};
|
||||
std::istringstream iss(source);
|
||||
iss >> std::get_time(&result, "%Y-%m-%d %H:%M:%S");
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, time_type_t>>* = nullptr) {
|
||||
std::tm result{};
|
||||
std::istringstream iss(source);
|
||||
iss >> std::get_time(&result, "%Y-%m-%d %H:%M:%S");
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, timestamp>>* = nullptr) {
|
||||
std::tm result{};
|
||||
std::istringstream iss(source);
|
||||
iss >> std::get_time(&result, "%Y-%m-%d %H:%M:%S");
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_integral_v<DestType> && !std::is_same_v<bool, DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_integral_v<DestType> && !std::is_same_v<bool, DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_integral_v<DestType> && !std::is_same_v<bool, DestType> && std::is_same_v<timestamp, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<bool, DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<bool, DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<bool, DestType> && std::is_same_v<timestamp, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<DestType> && std::is_same_v<timestamp, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob, DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob, DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob, DestType> && std::is_same_v<timestamp, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<std::string, DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<std::string, DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<std::string, DestType> && std::is_same_v<timestamp, SourceType>>* = nullptr) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //MATADOR_CONVERT_HPP
|
||||
|
||||
Reference in New Issue
Block a user