Compare commits

...

8 Commits

61 changed files with 219 additions and 200 deletions

View File

@ -38,7 +38,7 @@ public:
utils::result<std::vector<object::attribute>, utils::error> describe(const std::string& table) override; utils::result<std::vector<object::attribute>, utils::error> describe(const std::string& table) override;
utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override; utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override;
[[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override; [[nodiscard]] std::string to_escaped_string( const utils::blob_type_t& value ) const override;
private: private:
[[nodiscard]] static std::string generate_statement_name(const sql::query_context &query) ; [[nodiscard]] static std::string generate_statement_name(const sql::query_context &query) ;

View File

@ -33,12 +33,12 @@ public:
void write_value(size_t pos, const double &x) override; void write_value(size_t pos, const double &x) override;
void write_value(size_t pos, const utils::date_type_t &x ) override; void write_value(size_t pos, const utils::date_type_t &x ) override;
void write_value(size_t pos, const utils::time_type_t &x ) override; void write_value(size_t pos, const utils::time_type_t &x ) override;
void write_value(size_t pos, const utils::timestamp &x ) override; void write_value(size_t pos, const utils::timestamp_type_t &x ) override;
void write_value(size_t pos, const char *x) override; void write_value(size_t pos, const char *x) override;
void write_value(size_t pos, const char *x, size_t size) override; void write_value(size_t pos, const char *x, size_t size) override;
void write_value(size_t pos, const std::string &x) override; void write_value(size_t pos, const std::string &x) override;
void write_value(size_t pos, const std::string &x, size_t size) override; void write_value(size_t pos, const std::string &x, size_t size) override;
void write_value(size_t pos, const utils::blob &x) override; void write_value(size_t pos, const utils::blob_type_t &x) override;
void write_value(size_t pos, const utils::value &x, size_t size) override; void write_value(size_t pos, const utils::value &x, size_t size) override;
[[nodiscard]] const bind_data& params() const; [[nodiscard]] const bind_data& params() const;

View File

@ -24,11 +24,11 @@ public:
void read_value(const char *, size_t, double &) override {} void read_value(const char *, size_t, double &) override {}
void read_value(const char *, size_t, utils::date_type_t &) override {} void read_value(const char *, size_t, utils::date_type_t &) override {}
void read_value(const char *, size_t, utils::time_type_t &) override {} void read_value(const char *, size_t, utils::time_type_t &) override {}
void read_value(const char *, size_t, utils::timestamp &) override {} void read_value(const char *, size_t, utils::timestamp_type_t &) override {}
void read_value(const char *, size_t, char *, size_t) override {} void read_value(const char *, size_t, char *, size_t) override {}
void read_value(const char *, size_t, std::string &) override {} void read_value(const char *, size_t, std::string &) override {}
void read_value(const char *, size_t, std::string &, size_t) override {} void read_value(const char *, size_t, std::string &, size_t) override {}
void read_value(const char *, size_t, utils::blob &) override {} void read_value(const char *, size_t, utils::blob_type_t &) override {}
void read_value(const char *, size_t, utils::value &, size_t) override {} void read_value(const char *, size_t, utils::value &, size_t) override {}
}; };
@ -58,11 +58,11 @@ public:
void read_value(const char *id, size_t index, double &value) override; void read_value(const char *id, size_t index, double &value) override;
void read_value(const char *id, size_t index, utils::date_type_t &) override; void read_value(const char *id, size_t index, utils::date_type_t &) override;
void read_value(const char *id, size_t index, utils::time_type_t &) override; void read_value(const char *id, size_t index, utils::time_type_t &) override;
void read_value(const char *id, size_t index, utils::timestamp &) override; void read_value(const char *id, size_t index, utils::timestamp_type_t &) override;
void read_value(const char *id, size_t index, char *value, size_t size) override; void read_value(const char *id, size_t index, char *value, size_t size) override;
void read_value(const char *id, size_t index, std::string &value) override; void read_value(const char *id, size_t index, std::string &value) override;
void read_value(const char *id, size_t index, std::string &value, size_t size) override; void read_value(const char *id, size_t index, std::string &value, size_t size) override;
void read_value(const char *id, size_t index, utils::blob &value) override; void read_value(const char *id, size_t index, utils::blob_type_t &value) override;
void read_value(const char *id, size_t index, utils::value &val, size_t size) override; void read_value(const char *id, size_t index, utils::value &val, size_t size) override;
protected: protected:

View File

@ -293,7 +293,7 @@ utils::result<bool, utils::error> postgres_connection::exists(const std::string
return utils::ok(*result == 1); return utils::ok(*result == 1);
} }
std::string postgres_connection::to_escaped_string(const utils::blob &value) const { std::string postgres_connection::to_escaped_string(const utils::blob_type_t &value) const {
size_t escapedDataLength; size_t escapedDataLength;
unsigned char *escapedData = PQescapeByteaConn(conn_, value.data(), value.size(), &escapedDataLength); unsigned char *escapedData = PQescapeByteaConn(conn_, value.data(), value.size(), &escapedDataLength);

View File

@ -145,10 +145,10 @@ void postgres_parameter_binder::write_value(const size_t pos, const utils::time_
bind_data_.formats[pos] = 0; bind_data_.formats[pos] = 0;
} }
void postgres_parameter_binder::write_value(size_t pos, const utils::timestamp &x) { void postgres_parameter_binder::write_value(size_t pos, const utils::timestamp_type_t &x) {
} }
void postgres_parameter_binder::write_value(const size_t pos, const utils::blob &x) { void postgres_parameter_binder::write_value(const size_t pos, const utils::blob_type_t &x) {
bind_data_.bytes[pos] = x; bind_data_.bytes[pos] = x;
bind_data_.values[pos] = reinterpret_cast<char *>(bind_data_.bytes[pos].data()); bind_data_.values[pos] = reinterpret_cast<char *>(bind_data_.bytes[pos].data());
bind_data_.lengths[pos] = static_cast<int>(bind_data_.bytes[pos].size()); bind_data_.lengths[pos] = static_cast<int>(bind_data_.bytes[pos].size());

View File

@ -114,7 +114,7 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
} }
} }
void postgres_result_reader::read_value(const char * /*id*/, size_t index, utils::timestamp &value) { void postgres_result_reader::read_value(const char * /*id*/, size_t index, utils::timestamp_type_t &value) {
if (const auto val = column(index); strlen(val) > 0) { if (const auto val = column(index); strlen(val) > 0) {
} }
} }
@ -145,7 +145,7 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
value.assign(column(index)); value.assign(column(index));
} }
void postgres_result_reader::read_value(const char * /*id*/, const size_t index, utils::blob &value) { void postgres_result_reader::read_value(const char * /*id*/, const size_t index, utils::blob_type_t &value) {
const auto *data = reinterpret_cast<const unsigned char *>(column(index)); const auto *data = reinterpret_cast<const unsigned char *>(column(index));
size_t length; size_t length;
@ -164,11 +164,11 @@ void set_value(const char *str, utils::value &value) {
} }
template<> template<>
void set_value<utils::blob>(const char *str, utils::value &value) { void set_value<utils::blob_type_t>(const char *str, utils::value &value) {
size_t length; size_t length;
unsigned char *unescaped = PQunescapeBytea(reinterpret_cast<const unsigned char *>(str), &length); unsigned char *unescaped = PQunescapeBytea(reinterpret_cast<const unsigned char *>(str), &length);
value = utils::blob(unescaped, unescaped + length); value = utils::blob_type_t(unescaped, unescaped + length);
PQfreemem(unescaped); PQfreemem(unescaped);
} }
@ -224,7 +224,7 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
set_value<utils::date_type_t>(column(index), val); set_value<utils::date_type_t>(column(index), val);
break; break;
case utils::basic_type::DateTime: { case utils::basic_type::DateTime: {
set_value<utils::timestamp>(column(index), val); set_value<utils::timestamp_type_t>(column(index), val);
break; break;
} }
case utils::basic_type::Null: { case utils::basic_type::Null: {
@ -232,7 +232,7 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
break; break;
} }
case utils::basic_type::Blob: { case utils::basic_type::Blob: {
set_value<utils::blob>(column(index), val); set_value<utils::blob_type_t>(column(index), val);
break; break;
} }
case utils::basic_type::Unknown: case utils::basic_type::Unknown:

View File

@ -21,18 +21,10 @@
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
#include "matador/query/schema.hpp"
#include "matador/orm/session.hpp" #include "matador/orm/session.hpp"
template <> struct matador::utils::data_type_traits<work::core::timestamp, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
}
static void bind_value(attribute_writer &/*binder*/, size_t /*index*/, nullptr_t &/*value*/) {
}
};
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> { template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; } static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) { static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
@ -70,46 +62,47 @@ using namespace work::models;
// payload.is_polymorphic_type<jobs::IdPayload>(); // payload.is_polymorphic_type<jobs::IdPayload>();
int main() { int main() {
// logger::default_min_log_level(logger::log_level::LVL_DEBUG); logger::default_min_log_level(logger::log_level::LVL_DEBUG);
// logger::add_log_sink(logger::create_stdout_sink()); logger::add_log_sink(logger::create_stdout_sink());
// sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4); // sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
sql::connection_pool pool("postgres://test:test123!@127.0.0.1:5432/matador", 4); sql::connection_pool pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
object::repository repo("Administration");
auto result = repo.attach<admin::CollectionCenter>("collection_centers");
// repo.create(pool);
// repo.drop(pool);
utils::message_bus bus; utils::message_bus bus;
orm::session ses({bus, pool}); // query::schema ses({bus, pool});
query::schema admin_schema("Administration");
result = ses.attach<admin::CollectionCenter>("collection_centers") auto result = admin_schema.attach<admin::CollectionCenter>("collection_centers")
.and_then([&ses] { return ses.attach<admin::UserDirectory>("user_directories"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::UserDirectory>("user_directories"); })
.and_then([&ses] { return ses.attach<admin::LdapGroupSchemaSettings>("ldap_group_schema_settings"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::LdapGroupSchemaSettings>("ldap_group_schema_settings"); })
.and_then([&ses] { return ses.attach<admin::LdapImportSettings>("ldap_import_settings"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::LdapImportSettings>("ldap_import_settings"); })
.and_then([&ses] { return ses.attach<admin::LdapUserSchemaSettings>("ldap_user_schema_settings"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::LdapUserSchemaSettings>("ldap_user_schema_settings"); })
.and_then([&ses] { return ses.attach<admin::InternalUserDirectory, admin::UserDirectory>("internal_user_directories"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::InternalUserDirectory, admin::UserDirectory>("internal_user_directories"); })
.and_then([&ses] { return ses.attach<admin::LdapUserDirectory, admin::UserDirectory>("ldap_user_directories"); } ) .and_then([&admin_schema] { return admin_schema.attach<admin::LdapUserDirectory, admin::UserDirectory>("ldap_user_directories"); } )
.and_then([&ses] { return ses.attach<admin::LoginHistory>("login_histories"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::LoginHistory>("login_histories"); })
.and_then([&ses] { return ses.attach<admin::Scenario>("scenarios"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::Scenario>("scenarios"); })
.and_then([&ses] { return ses.attach<admin::User>("users"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::User>("users"); })
.and_then([&ses] { return ses.attach<admin::UserSession>("user_sessions"); }) .and_then([&admin_schema] { return admin_schema.attach<admin::UserSession>("user_sessions"); })
.and_then([&ses] { return ses.attach<jobs::Job>("jobs"); }) .and_then([&admin_schema] { return admin_schema.attach<jobs::Job>("jobs"); })
.and_then([&ses] { return ses.attach<jobs::Payload>("payloads"); }) .and_then([&admin_schema] { return admin_schema.attach<jobs::Payload>("payloads"); })
.and_then([&ses] { return ses.attach<jobs::IdPayload, jobs::Payload>("id_list_payloads"); }) .and_then([&admin_schema] { return admin_schema.attach<jobs::IdPayload, jobs::Payload>("id_list_payloads"); })
.and_then([&ses] { return ses.attach<jobs::IdListPayload, jobs::Payload>("id_payloads"); }) .and_then([&admin_schema] { return admin_schema.attach<jobs::IdListPayload, jobs::Payload>("id_payloads"); })
.and_then([&ses] { return ses.attach<jobs::Task>("tasks"); }) .and_then([&admin_schema] { return admin_schema.attach<jobs::Task>("tasks"); })
; ;
ses.dump_schema(std::cout); admin_schema.dump(std::cout);
if (!result) { if (!result) {
std::cout << "error: " << result.err().message() << std::endl; std::cout << "error: " << result.err().message() << std::endl;
return 0; return 0;
} }
result = ses.create_schema(); const auto conn = pool.acquire();
result = admin_schema.create(*conn);
if (!result) {
std::cout << "error: " << result.err() << std::endl;
return 0;
}
result = admin_schema.drop(*conn);
if (!result) { if (!result) {
std::cout << "error: " << result.err() << std::endl; std::cout << "error: " << result.err() << std::endl;
return 0; return 0;

View File

@ -11,6 +11,8 @@
#include "matador/utils/fetch_type.hpp" #include "matador/utils/fetch_type.hpp"
#include "matador/utils/types.hpp" #include "matador/utils/types.hpp"
#include "matador/query/meta_table_macro.hpp"
namespace work::models::admin { namespace work::models::admin {
struct User; struct User;
@ -28,7 +30,7 @@ static const matador::utils::enum_mapper<CollectionCenterType> CollectionCenterT
struct CollectionCenter : core::Model { struct CollectionCenter : core::Model {
std::string name; std::string name;
matador::utils::blob symbol; matador::utils::blob_type_t symbol;
CollectionCenterType type{CollectionCenterType::NoType}; CollectionCenterType type{CollectionCenterType::NoType};
matador::object::collection<matador::object::object_ptr<User>> users; matador::object::collection<matador::object::object_ptr<User>> users;
@ -45,4 +47,6 @@ struct CollectionCenter : core::Model {
} }
META_TABLE(collection_center, COLLECTION_CENTER, id, version, name, symbol, type)
#endif //COLLECTION_CENTER_HPP #endif //COLLECTION_CENTER_HPP

View File

@ -4,6 +4,7 @@
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
struct LdapUserDirectory; struct LdapUserDirectory;
@ -17,7 +18,7 @@ struct LdapGroupSchemaSettings : core::Model {
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) ); field::process( op, *matador::base_class<Model>( this ) );
field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::default_foreign_attributes); field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::CascadeAllFetchLazy);
field::attribute( op, "group_object_filter", group_object_filter, 511 ); field::attribute( op, "group_object_filter", group_object_filter, 511 );
field::attribute( op, "user_member_attribute", user_member_attribute, 511 ); field::attribute( op, "user_member_attribute", user_member_attribute, 511 );
} }

View File

@ -4,6 +4,7 @@
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
struct LdapUserDirectory; struct LdapUserDirectory;
@ -18,7 +19,7 @@ struct LdapImportSettings : core::Model {
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) ); field::process( op, *matador::base_class<Model>( this ) );
field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::default_foreign_attributes); field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::CascadeAllFetchLazy);
field::attribute( op, "default_role", default_role, 511 ); field::attribute( op, "default_role", default_role, 511 );
field::attribute( op, "sync_interval", sync_interval ); field::attribute( op, "sync_interval", sync_interval );
field::attribute( op, "network_timeout", network_timeout ); field::attribute( op, "network_timeout", network_timeout );

View File

@ -10,6 +10,7 @@
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
struct LdapUserDirectory : UserDirectory { struct LdapUserDirectory : UserDirectory {
@ -29,11 +30,11 @@ struct LdapUserDirectory : UserDirectory {
field::attribute( op, "schema_base_dn", schema_base_dn, 511 ); field::attribute( op, "schema_base_dn", schema_base_dn, 511 );
field::attribute( op, "additional_user_base_dn", additional_user_base_dn, 511 ); field::attribute( op, "additional_user_base_dn", additional_user_base_dn, 511 );
field::attribute( op, "additional_group_base_dn", additional_group_base_dn, 511 ); field::attribute( op, "additional_group_base_dn", additional_group_base_dn, 511 );
field::belongs_to( op, "user_schema_settings", user_schema_settings, matador::utils::default_foreign_attributes ); field::belongs_to( op, "user_schema_settings", user_schema_settings, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "group_schema_settings", group_schema_settings, matador::utils::default_foreign_attributes ); field::belongs_to( op, "group_schema_settings", group_schema_settings, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "import_settings", import_settings, matador::utils::default_foreign_attributes ); field::belongs_to( op, "import_settings", import_settings, matador::utils::CascadeAllFetchLazy );
field::has_many( op, "ldap_users", users, "users_id", matador::utils::default_foreign_attributes ); field::has_many( op, "ldap_users", users, "users_id", matador::utils::CascadeAllFetchLazy );
field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::default_foreign_attributes ); field::has_many( op, "ldap_groups", groups, "groups_id", matador::utils::CascadeAllFetchLazy );
} }
}; };
} }

View File

@ -4,7 +4,7 @@
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
struct LdapUserDirectory; struct LdapUserDirectory;
@ -20,7 +20,7 @@ struct LdapUserSchemaSettings : core::Model {
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process(op, *matador::base_class<Model>( this )); field::process(op, *matador::base_class<Model>( this ));
field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::default_foreign_attributes); field::has_one(op, "ldap_user_directory", ldap_user_directory, matador::utils::CascadeAllFetchLazy);
field::attribute(op, "user_object_filter", user_object_filter, 511); field::attribute(op, "user_object_filter", user_object_filter, 511);
field::attribute(op, "user_unique_id_attribute", user_unique_id_attribute, 511); field::attribute(op, "user_unique_id_attribute", user_unique_id_attribute, 511);
field::attribute(op, "user_member_of_attribute", user_member_of_attribute, 511); field::attribute(op, "user_member_of_attribute", user_member_of_attribute, 511);

View File

@ -11,6 +11,7 @@
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/enum_mapper.hpp" #include "matador/utils/enum_mapper.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
@ -39,20 +40,20 @@ static const matador::utils::enum_mapper<FailReason> FailReasonEnum({
}); });
struct LoginHistory : core::Model { struct LoginHistory : core::Model {
matador::object::object_ptr<User> user; matador::object::object_ptr<User> client;
matador::object::object_ptr<Scenario> scenario; matador::object::object_ptr<Scenario> scenario;
matador::object::object_ptr<CollectionCenter> collection_center; matador::object::object_ptr<CollectionCenter> collection_center;
std::string login_name; std::string login_name;
FailReason fail_reason{FailReason::NoFailReason}; FailReason fail_reason{FailReason::NoFailReason};
core::timestamp login_time; matador::utils::timestamp_type_t login_time;
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) ); field::process( op, *matador::base_class<Model>( this ) );
field::belongs_to( op, "user", user, matador::utils::default_foreign_attributes ); field::belongs_to( op, "client", client, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "scenario", scenario, matador::utils::default_foreign_attributes ); field::belongs_to( op, "scenario", scenario, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "collection_center", collection_center, matador::utils::default_foreign_attributes ); field::belongs_to( op, "collection_center", collection_center, matador::utils::CascadeAllFetchLazy );
field::attribute( op, "login_name", login_name, 511 ); field::attribute( op, "login_name", login_name, 511 );
field::attribute( op, "fail_reason", fail_reason ); field::attribute( op, "fail_reason", fail_reason );
field::attribute( op, "login_time", login_time ); field::attribute( op, "login_time", login_time );

View File

@ -40,7 +40,7 @@ struct Scenario : core::Model {
std::string name; std::string name;
ScenarioMode mode{ScenarioMode::InvalidMode}; ScenarioMode mode{ScenarioMode::InvalidMode};
std::string description; std::string description;
matador::utils::blob symbol; matador::utils::blob_type_t symbol;
ScenarioState state{ScenarioState::InvalidState}; ScenarioState state{ScenarioState::InvalidState};
matador::object::collection<matador::object::object_ptr<CollectionCenter>> collection_center; matador::object::collection<matador::object::object_ptr<CollectionCenter>> collection_center;

View File

@ -4,11 +4,11 @@
#include "LockType.hpp" #include "LockType.hpp"
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
#include "matador/utils/types.hpp" #include "matador/utils/types.hpp"
namespace work::models::admin { namespace work::models::admin {
@ -16,11 +16,11 @@ struct UserDirectory;
struct User : core::Model { struct User : core::Model {
std::string name; std::string name;
matador::utils::blob symbol; matador::utils::blob_type_t symbol;
std::string salt; std::string salt;
std::string password; std::string password;
LockType lock_type{LockType::NoLock}; LockType lock_type{LockType::NoLock};
core::timestamp locked_at; matador::utils::timestamp_type_t locked_at;
std::string lock_reason; std::string lock_reason;
std::string role; std::string role;
matador::object::object_ptr<UserDirectory> user_directory; matador::object::object_ptr<UserDirectory> user_directory;
@ -37,7 +37,7 @@ struct User : core::Model {
field::attribute( op, "locked_at", locked_at ); field::attribute( op, "locked_at", locked_at );
field::attribute( op, "lock_reason", lock_reason, 511 ); field::attribute( op, "lock_reason", lock_reason, 511 );
field::attribute( op, "role", role, 63 ); field::attribute( op, "role", role, 63 );
field::belongs_to( op, "user_directory", user_directory, matador::utils::default_foreign_attributes ); field::belongs_to( op, "user_directory", user_directory, matador::utils::CascadeAllFetchLazy );
} }
}; };

View File

@ -6,26 +6,26 @@
#include "User.hpp" #include "User.hpp"
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::admin { namespace work::models::admin {
struct UserSession : core::Model { struct UserSession : core::Model {
matador::object::object_ptr<User> user; matador::object::object_ptr<User> client;
matador::object::object_ptr<Scenario> scenario; matador::object::object_ptr<Scenario> scenario;
matador::object::object_ptr<CollectionCenter> collection_center; matador::object::object_ptr<CollectionCenter> collection_center;
core::timestamp offline_since; matador::utils::timestamp_type_t offline_since;
template<typename Operator> template<typename Operator>
void process( Operator& op ) { void process( Operator& op ) {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) ); field::process( op, *matador::base_class<Model>( this ) );
field::belongs_to( op, "user", user, matador::utils::default_foreign_attributes ); field::belongs_to( op, "client", client, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "scenario", scenario, matador::utils::default_foreign_attributes ); field::belongs_to( op, "scenario", scenario, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "collection_center", collection_center, matador::utils::default_foreign_attributes ); field::belongs_to( op, "collection_center", collection_center, matador::utils::CascadeAllFetchLazy );
field::attribute( op, "offline_since", offline_since ); field::attribute( op, "offline_since", offline_since );
} }
}; };

View File

@ -1,9 +0,0 @@
#ifndef TYPES_HPP
#define TYPES_HPP
#include <chrono>
namespace work::core {
using timestamp = std::chrono::system_clock::time_point;
}
#endif //TYPES_HPP

View File

@ -7,12 +7,12 @@
#include "Task.hpp" #include "Task.hpp"
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "../core/UserInfo.hpp" #include "../core/UserInfo.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::jobs { namespace work::models::jobs {
@ -21,7 +21,7 @@ struct Job : core::Model {
std::string description; std::string description;
JobState state; JobState state;
JobMode mode; JobMode mode;
core::timestamp created_at; matador::utils::timestamp_type_t created_at;
matador::object::object_ptr<Payload> payload; matador::object::object_ptr<Payload> payload;
matador::object::object_ptr<Task> task; matador::object::object_ptr<Task> task;
core::UserInfo user_info; core::UserInfo user_info;
@ -35,8 +35,8 @@ struct Job : core::Model {
field::attribute( op, "state", state ); field::attribute( op, "state", state );
field::attribute( op, "mode", mode ); field::attribute( op, "mode", mode );
field::attribute( op, "created_at", created_at ); field::attribute( op, "created_at", created_at );
field::has_one(op, "payload", payload, matador::utils::default_foreign_attributes ); field::has_one(op, "payload", payload, matador::utils::CascadeAllFetchLazy );
field::belongs_to( op, "task", task, matador::utils::default_foreign_attributes ); field::belongs_to( op, "task", task, matador::utils::CascadeAllFetchLazy );
field::attribute( op, "user_info", user_info ); field::attribute( op, "user_info", user_info );
} }
}; };

View File

@ -4,6 +4,7 @@
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::jobs { namespace work::models::jobs {
struct Job; struct Job;
@ -16,7 +17,7 @@ struct Payload : core::Model {
namespace field = matador::access; namespace field = matador::access;
field::process( op, *matador::base_class<Model>( this ) ); field::process( op, *matador::base_class<Model>( this ) );
field::attribute( op, "type", type, 255 ); field::attribute( op, "type", type, 255 );
field::belongs_to( op, "job", job, matador::utils::default_foreign_attributes ); field::belongs_to( op, "job", job, matador::utils::CascadeAllFetchLazy );
} }
}; };
} }

View File

@ -4,11 +4,11 @@
#include "TaskState.hpp" #include "TaskState.hpp"
#include "../core/Model.hpp" #include "../core/Model.hpp"
#include "../core/Types.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/utils/base_class.hpp" #include "matador/utils/base_class.hpp"
#include "matador/utils/foreign_attributes.hpp"
namespace work::models::jobs { namespace work::models::jobs {
struct Task : core::Model { struct Task : core::Model {
@ -18,8 +18,8 @@ struct Task : core::Model {
TaskState state; TaskState state;
matador::object::object_ptr<Payload> payload; matador::object::object_ptr<Payload> payload;
JobMode job_mode; JobMode job_mode;
core::timestamp start_delay; matador::utils::timestamp_type_t start_delay;
core::timestamp interval; matador::utils::timestamp_type_t interval;
uint64_t user_session_id; uint64_t user_session_id;
template<typename Operator> template<typename Operator>
@ -30,7 +30,7 @@ struct Task : core::Model {
field::attribute( op, "description", description, 511 ); field::attribute( op, "description", description, 511 );
field::attribute( op, "job_name", job_name, 511 ); field::attribute( op, "job_name", job_name, 511 );
field::attribute( op, "state", state ); field::attribute( op, "state", state );
field::belongs_to( op, "payload", payload, matador::utils::default_foreign_attributes ); field::belongs_to( op, "payload", payload, matador::utils::CascadeAllFetchLazy );
field::attribute( op, "job_mode", job_mode ); field::attribute( op, "job_mode", job_mode );
field::attribute( op, "start_delay", start_delay ); field::attribute( op, "start_delay", start_delay );
field::attribute( op, "interval", interval ); field::attribute( op, "interval", interval );

View File

@ -211,7 +211,7 @@ void relation_completer<Type, Observers...>::on_has_many(const char *id, Collect
link_relation_endpoints(local_endpoint, foreign_endpoint); link_relation_endpoints(local_endpoint, foreign_endpoint);
const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, *foreign_node); const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, *foreign_node);
node->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint); attached_node->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint);
} }
} }

View File

@ -118,8 +118,6 @@ public:
[[nodiscard]] std::vector<object::attribute> describe_table(const std::string &table_name) const; [[nodiscard]] std::vector<object::attribute> describe_table(const std::string &table_name) const;
[[nodiscard]] bool table_exists(const std::string &table_name) const; [[nodiscard]] bool table_exists(const std::string &table_name) const;
void dump_schema(std::ostream &os) const;
[[nodiscard]] utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &ctx) const override; [[nodiscard]] utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &ctx) const override;
[[nodiscard]] utils::result<size_t, utils::error> execute(const sql::query_context &ctx) const override; [[nodiscard]] utils::result<size_t, utils::error> execute(const sql::query_context &ctx) const override;
[[nodiscard]] utils::result<sql::statement, utils::error> prepare(const sql::query_context &ctx) override; [[nodiscard]] utils::result<sql::statement, utils::error> prepare(const sql::query_context &ctx) override;

View File

@ -40,12 +40,12 @@ public:
void write_value(size_t pos, const double& x) override; void write_value(size_t pos, const double& x) override;
void write_value(size_t pos, const utils::date_type_t& x) override; void write_value(size_t pos, const utils::date_type_t& x) override;
void write_value(size_t pos, const utils::time_type_t& x) override; void write_value(size_t pos, const utils::time_type_t& x) override;
void write_value(size_t pos, const utils::timestamp& x) override; void write_value(size_t pos, const utils::timestamp_type_t& x) override;
void write_value(size_t pos, const char* x) override; void write_value(size_t pos, const char* x) override;
void write_value(size_t pos, const char* x, size_t size) override; void write_value(size_t pos, const char* x, size_t size) override;
void write_value(size_t pos, const std::string& x) override; void write_value(size_t pos, const std::string& x) override;
void write_value(size_t pos, const std::string& x, size_t size) override; void write_value(size_t pos, const std::string& x, size_t size) override;
void write_value(size_t pos, const utils::blob& x) override; void write_value(size_t pos, const utils::blob_type_t& x) override;
void write_value(size_t pos, const utils::value& x, size_t size) override; void write_value(size_t pos, const utils::value& x, size_t size) override;
private: private:

View File

@ -33,8 +33,8 @@ struct basic_type_to_string_visitor
void operator()(const std::string &x) { result = writer->to_string(x); } void operator()(const std::string &x) { result = writer->to_string(x); }
void operator()(const utils::date_type_t &x) { result = writer->to_string(x); } void operator()(const utils::date_type_t &x) { result = writer->to_string(x); }
void operator()(const utils::time_type_t &x) { result = writer->to_string(x); } void operator()(const utils::time_type_t &x) { result = writer->to_string(x); }
void operator()(const utils::timestamp &x) { result = writer->to_string(x); } void operator()(const utils::timestamp_type_t &x) { result = writer->to_string(x); }
void operator()(const utils::blob &x) { result = writer->to_string(x); } void operator()(const utils::blob_type_t &x) { result = writer->to_string(x); }
attribute_string_writer *writer{}; attribute_string_writer *writer{};
sql::query_context &query; sql::query_context &query;

View File

@ -111,6 +111,8 @@ public:
const object::repository &repo() const { return repo_; } const object::repository &repo() const { return repo_; }
object::repository &repo() { return repo_; } object::repository &repo() { return repo_; }
void dump(std::ostream &os) const;
private: private:
[[nodiscard]] sql::query_context build_add_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const; [[nodiscard]] sql::query_context build_add_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const;
[[nodiscard]] sql::query_context build_drop_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const; [[nodiscard]] sql::query_context build_drop_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const;

View File

@ -73,12 +73,12 @@ public:
void write_value(size_t pos, const double &x) override; void write_value(size_t pos, const double &x) override;
void write_value(size_t pos, const utils::date_type_t &x ) override; void write_value(size_t pos, const utils::date_type_t &x ) override;
void write_value(size_t pos, const utils::time_type_t &x ) override; void write_value(size_t pos, const utils::time_type_t &x ) override;
void write_value(size_t pos, const utils::timestamp &x ) override; void write_value(size_t pos, const utils::timestamp_type_t &x ) override;
void write_value(size_t pos, const char *x) override; void write_value(size_t pos, const char *x) override;
void write_value(size_t pos, const char *x, size_t size) override; void write_value(size_t pos, const char *x, size_t size) override;
void write_value(size_t pos, const std::string &x) override; void write_value(size_t pos, const std::string &x) override;
void write_value(size_t pos, const std::string &x, size_t size) override; void write_value(size_t pos, const std::string &x, size_t size) override;
void write_value(size_t pos, const utils::blob &x) override; void write_value(size_t pos, const utils::blob_type_t &x) override;
void write_value(size_t pos, const utils::value &x, size_t size) override; void write_value(size_t pos, const utils::value &x, size_t size) override;
private: private:

View File

@ -37,7 +37,7 @@ public:
using sql_func_to_string_map = std::unordered_map<sql_function_t, std::string>; using sql_func_to_string_map = std::unordered_map<sql_function_t, std::string>;
using next_placeholder_func = std::function<std::string(size_t)>; using next_placeholder_func = std::function<std::string(size_t)>;
using to_escaped_string_func = std::function<std::string(const utils::blob &)>; using to_escaped_string_func = std::function<std::string(const utils::blob_type_t &)>;
public: public:
[[nodiscard]] const std::string& token_at(dialect_token token) const; [[nodiscard]] const std::string& token_at(dialect_token token) const;
@ -115,7 +115,7 @@ public:
*/ */
[[nodiscard]] std::string next_placeholder(const std::vector<std::string> &bind_vars) const; [[nodiscard]] std::string next_placeholder(const std::vector<std::string> &bind_vars) const;
[[nodiscard]] std::string to_escaped_string(const utils::blob &value, const connection_impl *conn = nullptr) const; [[nodiscard]] std::string to_escaped_string(const utils::blob_type_t &value, const connection_impl *conn = nullptr) const;
/** /**
* Returns the default schema name. * Returns the default schema name.
@ -183,7 +183,7 @@ private:
friend class dialect_builder; friend class dialect_builder;
next_placeholder_func placeholder_func_ = [](size_t) { return "?"; }; next_placeholder_func placeholder_func_ = [](size_t) { return "?"; };
to_escaped_string_func to_escaped_string_func_ = [](const utils::blob &val) { return utils::to_string(val); }; to_escaped_string_func to_escaped_string_func_ = [](const utils::blob_type_t &val) { return utils::to_string(val); };
escape_identifier_t identifier_escape_type_ = escape_identifier_t::ESCAPE_BOTH_SAME; escape_identifier_t identifier_escape_type_ = escape_identifier_t::ESCAPE_BOTH_SAME;
@ -262,7 +262,8 @@ private:
{utils::basic_type::Time, "TIME"}, {utils::basic_type::Time, "TIME"},
{utils::basic_type::DateTime, "DATETIME"}, {utils::basic_type::DateTime, "DATETIME"},
{utils::basic_type::Blob, "BLOB"}, {utils::basic_type::Blob, "BLOB"},
{utils::basic_type::Null, "NULL"} {utils::basic_type::Null, "NULL"},
// {utils::basic_type::Unknown, "INTEGER"}
}; };
sql_func_to_string_map sql_func_map_ { sql_func_to_string_map sql_func_map_ {

View File

@ -13,7 +13,7 @@
#include "matador/utils/version.hpp" #include "matador/utils/version.hpp"
namespace matador::utils { namespace matador::utils {
using blob = std::vector<unsigned char>; using blob_type_t = std::vector<unsigned char>;
} }
namespace matador::sql { namespace matador::sql {
@ -43,7 +43,7 @@ public:
[[nodiscard]] const class dialect &dialect() const; [[nodiscard]] const class dialect &dialect() const;
[[nodiscard]] virtual std::string to_escaped_string(const utils::blob &value) const = 0; [[nodiscard]] virtual std::string to_escaped_string(const utils::blob_type_t &value) const = 0;
[[nodiscard]] const connection_info &info() const; [[nodiscard]] const connection_info &info() const;
protected: protected:

View File

@ -27,11 +27,11 @@ public:
virtual void read_value(const char *id, size_t index, double &value) = 0; virtual void read_value(const char *id, size_t index, double &value) = 0;
virtual void read_value(const char *id, size_t index, time_type_t &value) = 0; virtual void read_value(const char *id, size_t index, time_type_t &value) = 0;
virtual void read_value(const char *id, size_t index, date_type_t &value) = 0; virtual void read_value(const char *id, size_t index, date_type_t &value) = 0;
virtual void read_value(const char *id, size_t index, timestamp &value) = 0; virtual void read_value(const char *id, size_t index, timestamp_type_t &value) = 0;
virtual void read_value(const char *id, size_t index, char *value, size_t size) = 0; virtual void read_value(const char *id, size_t index, char *value, size_t size) = 0;
virtual void read_value(const char *id, size_t index, std::string &value) = 0; virtual void read_value(const char *id, size_t index, std::string &value) = 0;
virtual void read_value(const char *id, size_t index, std::string &value, size_t size) = 0; virtual void read_value(const char *id, size_t index, std::string &value, size_t size) = 0;
virtual void read_value(const char *id, size_t index, blob &value) = 0; virtual void read_value(const char *id, size_t index, blob_type_t &value) = 0;
virtual void read_value(const char *id, size_t index, value &value, size_t size) = 0; virtual void read_value(const char *id, size_t index, value &value, size_t size) = 0;
}; };

View File

@ -27,12 +27,12 @@ public:
virtual void write_value(size_t pos, const double &x) = 0; virtual void write_value(size_t pos, const double &x) = 0;
virtual void write_value(size_t pos, const date_type_t &x) = 0; virtual void write_value(size_t pos, const date_type_t &x) = 0;
virtual void write_value(size_t pos, const time_type_t &x) = 0; virtual void write_value(size_t pos, const time_type_t &x) = 0;
virtual void write_value(size_t pos, const timestamp &x) = 0; virtual void write_value(size_t pos, const timestamp_type_t &x) = 0;
virtual void write_value(size_t pos, const char *x) = 0; virtual void write_value(size_t pos, const char *x) = 0;
virtual void write_value(size_t pos, const char *x, size_t size) = 0; virtual void write_value(size_t pos, const char *x, size_t size) = 0;
virtual void write_value(size_t pos, const std::string &x) = 0; virtual void write_value(size_t pos, const std::string &x) = 0;
virtual void write_value(size_t pos, const std::string &x, size_t size) = 0; virtual void write_value(size_t pos, const std::string &x, size_t size) = 0;
virtual void write_value(size_t pos, const blob &x) = 0; virtual void write_value(size_t pos, const blob_type_t &x) = 0;
virtual void write_value(size_t pos, const value &x, size_t size) = 0; virtual void write_value(size_t pos, const value &x, size_t size) = 0;
}; };

View File

@ -33,8 +33,8 @@ public:
void operator()(std::string &x) { this->convert(x); } void operator()(std::string &x) { this->convert(x); }
void operator()(date_type_t &x) { this->convert(x); } void operator()(date_type_t &x) { this->convert(x); }
void operator()(time_type_t &x) { this->convert(x); } void operator()(time_type_t &x) { this->convert(x); }
void operator()(timestamp &x) { this->convert(x); } void operator()(timestamp_type_t &x) { this->convert(x); }
void operator()(blob &x) { this->convert(x); } void operator()(blob_type_t &x) { this->convert(x); }
private: private:
result<Type, conversion_error> result_{}; result<Type, conversion_error> result_{};

View File

@ -158,7 +158,7 @@ result<DestType, conversion_error> to(const std::string &source, std::enable_if_
} }
template < typename DestType > template < typename DestType >
result<DestType, conversion_error> to(const blob &source, std::enable_if_t<std::is_same_v<DestType, blob>>* = nullptr) { result<DestType, conversion_error> to(const blob_type_t &source, std::enable_if_t<std::is_same_v<DestType, blob_type_t>>* = nullptr) {
return ok(source); return ok(source);
} }
@ -211,7 +211,7 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, blob> &&std::is_same_v<DestType, std::string>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, blob_type_t> &&std::is_same_v<DestType, std::string>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -224,12 +224,12 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_arithmetic_v<DestType> && std::is_same_v<SourceType, blob>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_arithmetic_v<DestType> && std::is_same_v<SourceType, blob_type_t>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t<std::is_integral_v<SourceType> && std::is_same_v<DestType, blob>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t<std::is_integral_v<SourceType> && std::is_same_v<DestType, blob_type_t>>* = nullptr) {
DestType result; DestType result;
result.resize(sizeof(source)); result.resize(sizeof(source));
std::memcpy(result.data(), &source, sizeof(source)); std::memcpy(result.data(), &source, sizeof(source));
@ -238,17 +238,17 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<SourceType> && std::is_same_v<DestType, blob>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<SourceType> && std::is_same_v<DestType, blob_type_t>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, std::string> && std::is_same_v<DestType, blob>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, std::string> && std::is_same_v<DestType, blob_type_t>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, const char*> && std::is_same_v<DestType, blob>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<SourceType, const char*> && std::is_same_v<DestType, blob_type_t>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -286,7 +286,7 @@ result<DestType, conversion_error> to(const char *source, std::enable_if_t<std::
template < typename DestType > template < typename DestType >
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, timestamp>>* = nullptr) { result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, timestamp_type_t>>* = nullptr) {
std::tm result{}; std::tm result{};
std::istringstream iss(source); std::istringstream iss(source);
iss >> std::get_time(&result, "%Y-%m-%d %H:%M:%S"); iss >> std::get_time(&result, "%Y-%m-%d %H:%M:%S");
@ -302,7 +302,7 @@ result<DestType, conversion_error> to(const std::string &source, std::enable_if_
} }
template < typename DestType > template < typename DestType >
result<DestType, conversion_error> to(const char *source, std::enable_if_t<std::is_same_v<DestType, timestamp>>* = nullptr) { result<DestType, conversion_error> to(const char *source, std::enable_if_t<std::is_same_v<DestType, timestamp_type_t>>* = nullptr) {
return to<DestType>(std::string{source}); return to<DestType>(std::string{source});
} }
@ -318,7 +318,7 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > 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) { 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_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -333,7 +333,7 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<bool, DestType> && std::is_same_v<timestamp_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -348,22 +348,22 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<DestType> && std::is_same_v<timestamp_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob_type_t, DestType> && std::is_same_v<date_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob_type_t, DestType> && std::is_same_v<time_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<blob_type_t, DestType> && std::is_same_v<timestamp_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -378,7 +378,7 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > 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) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_same_v<std::string, DestType> && std::is_same_v<timestamp_type_t, SourceType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -393,7 +393,7 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_integral_v<SourceType> && !std::is_same_v<bool, SourceType> && std::is_same_v<timestamp, DestType>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_integral_v<SourceType> && !std::is_same_v<bool, SourceType> && std::is_same_v<timestamp_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -408,22 +408,22 @@ result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_
} }
template < typename DestType, typename SourceType > template < typename DestType, typename SourceType >
result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<SourceType> && std::is_same_v<timestamp, DestType>>* = nullptr) { result<DestType, conversion_error> to(const SourceType &/*source*/, std::enable_if_t<std::is_floating_point_v<SourceType> && std::is_same_v<timestamp_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const blob &/*source*/, std::enable_if_t<std::is_same_v<date_type_t, DestType>>* = nullptr) { result<DestType, conversion_error> to(const blob_type_t &/*source*/, std::enable_if_t<std::is_same_v<date_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const blob &/*source*/, std::enable_if_t<std::is_same_v<time_type_t, DestType>>* = nullptr) { result<DestType, conversion_error> to(const blob_type_t &/*source*/, std::enable_if_t<std::is_same_v<time_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const blob &/*source*/, std::enable_if_t<std::is_same_v<timestamp, DestType>>* = nullptr) { result<DestType, conversion_error> to(const blob_type_t &/*source*/, std::enable_if_t<std::is_same_v<timestamp_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -438,7 +438,7 @@ result<DestType, conversion_error> to(const bool &/*source*/, std::enable_if_t<s
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const bool &/*source*/, std::enable_if_t<std::is_same_v<timestamp, DestType>>* = nullptr) { result<DestType, conversion_error> to(const bool &/*source*/, std::enable_if_t<std::is_same_v<timestamp_type_t, DestType>>* = nullptr) {
return failure(conversion_error::NotConvertable); return failure(conversion_error::NotConvertable);
} }
@ -463,7 +463,7 @@ result<DestType, conversion_error> to(const date_type_t &source, std::enable_if_
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const timestamp &source, std::enable_if_t<std::is_same_v<time_type_t, DestType>>* = nullptr) { result<DestType, conversion_error> to(const timestamp_type_t &source, std::enable_if_t<std::is_same_v<time_type_t, DestType>>* = nullptr) {
const std::time_t tt = std::chrono::system_clock::to_time_t(source); const std::time_t tt = std::chrono::system_clock::to_time_t(source);
const std::tm* result = std::localtime(&tt); const std::tm* result = std::localtime(&tt);
@ -472,7 +472,7 @@ result<DestType, conversion_error> to(const timestamp &source, std::enable_if_t<
} }
template < typename DestType> template < typename DestType>
result<DestType, conversion_error> to(const timestamp &source, std::enable_if_t<std::is_same_v<date_type_t, DestType>>* = nullptr) { result<DestType, conversion_error> to(const timestamp_type_t &source, std::enable_if_t<std::is_same_v<date_type_t, DestType>>* = nullptr) {
const std::time_t tt = std::chrono::system_clock::to_time_t(source); const std::time_t tt = std::chrono::system_clock::to_time_t(source);
const std::tm* result = std::localtime(&tt); const std::tm* result = std::localtime(&tt);

View File

@ -131,10 +131,10 @@ struct data_type_traits<std::string, void> {
}; };
template<> template<>
struct data_type_traits<utils::blob, void> { struct data_type_traits<blob_type_t, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::Blob; } static basic_type type(std::size_t /*size*/) { return basic_type::Blob; }
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value, size_t /*size*/ = 0); static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob_type_t &value, size_t /*size*/ = 0);
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value, size_t /*size*/ = 0); static void bind_value(attribute_writer &binder, size_t index, utils::blob_type_t &value, size_t /*size*/ = 0);
}; };
template<> template<>
@ -151,6 +151,13 @@ struct data_type_traits<time_type_t, void> {
static void bind_value(attribute_writer &binder, size_t index, time_type_t &value); static void bind_value(attribute_writer &binder, size_t index, time_type_t &value);
}; };
template<>
struct data_type_traits<timestamp_type_t, void> {
static basic_type type(std::size_t /*size*/) { return basic_type::DateTime; }
static void read_value(attribute_reader &reader, const char *id, size_t index, timestamp_type_t &value);
static void bind_value(attribute_writer &binder, size_t index, timestamp_type_t &value);
};
template<typename EnumType> template<typename EnumType>
struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType> > > { struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType> > > {
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; } static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; }

View File

@ -18,7 +18,7 @@ namespace matador::utils {
* @param data Binary data to be converted * @param data Binary data to be converted
* @return Binary data as string * @return Binary data as string
*/ */
MATADOR_UTILS_API std::string to_string(const blob &data); MATADOR_UTILS_API std::string to_string(const blob_type_t &data);
MATADOR_UTILS_API std::string to_string(const date_type_t &data); MATADOR_UTILS_API std::string to_string(const date_type_t &data);
MATADOR_UTILS_API std::string to_string(const time_type_t &data); MATADOR_UTILS_API std::string to_string(const time_type_t &data);

View File

@ -12,8 +12,8 @@ namespace matador::utils {
enum class basic_type : uint8_t; enum class basic_type : uint8_t;
using byte = unsigned char; using byte = unsigned char;
using blob = std::vector<byte>; using blob_type_t = std::vector<byte>;
using timestamp = std::chrono::system_clock::time_point; using timestamp_type_t = std::chrono::system_clock::time_point;
struct date_type_t; struct date_type_t;
struct time_type_t; struct time_type_t;
@ -25,8 +25,8 @@ using database_type = std::variant<
bool, bool,
const char*, const char*,
std::string, std::string,
blob, blob_type_t,
timestamp, timestamp_type_t,
date_type_t, date_type_t,
time_type_t, time_type_t,
nullptr_t>; nullptr_t>;

View File

@ -14,7 +14,7 @@ template<typename Type>
size_t determine_size(const Type &/*val*/) { return 0; } size_t determine_size(const Type &/*val*/) { return 0; }
size_t determine_size(const std::string &val); size_t determine_size(const std::string &val);
size_t determine_size(const char *val); size_t determine_size(const char *val);
size_t determine_size(const blob &val); size_t determine_size(const blob_type_t &val);
} }

View File

@ -123,11 +123,11 @@ void data_type_traits<std::string>::bind_value(attribute_writer &binder, const s
binder.write_value(index, value, size); binder.write_value(index, value, size);
} }
void data_type_traits<blob>::read_value(attribute_reader &reader, const char *id, const size_t index, utils::blob &value, const size_t /*size*/) { void data_type_traits<blob_type_t>::read_value(attribute_reader &reader, const char *id, const size_t index, utils::blob_type_t &value, const size_t /*size*/) {
reader.read_value(id, index, value); reader.read_value(id, index, value);
} }
void data_type_traits<blob>::bind_value(attribute_writer &binder, const size_t index, blob &value, const size_t /*size*/) { void data_type_traits<blob_type_t>::bind_value(attribute_writer &binder, const size_t index, blob_type_t &value, const size_t /*size*/) {
binder.write_value(index, value); binder.write_value(index, value);
} }
@ -147,4 +147,11 @@ void data_type_traits<time_type_t>::bind_value(attribute_writer &binder, const s
binder.write_value(index, value); binder.write_value(index, value);
} }
void data_type_traits<timestamp_type_t>::read_value(attribute_reader &reader, const char *id, const size_t index, timestamp_type_t &value) {
reader.read_value(id, index, value);
}
void data_type_traits<timestamp_type_t>::bind_value(attribute_writer &binder, const size_t index, timestamp_type_t &value) {
binder.write_value(index, value);
}
} }

View File

@ -4,7 +4,7 @@
#include <sstream> #include <sstream>
namespace matador::utils { namespace matador::utils {
std::string to_string(const blob& data) { std::string to_string(const blob_type_t& data) {
static constexpr char HEXITS[] = "0123456789ABCDEF"; static constexpr char HEXITS[] = "0123456789ABCDEF";
std::string str(2 * data.size(), '\0'); std::string str(2 * data.size(), '\0');

View File

@ -96,10 +96,10 @@ void initialize_by_basic_type(const basic_type type, database_type &val) {
val.emplace<time_type_t>(); val.emplace<time_type_t>();
break; break;
case basic_type::DateTime: case basic_type::DateTime:
val.emplace<timestamp>(); val.emplace<timestamp_type_t>();
break; break;
case basic_type::Blob: case basic_type::Blob:
val.emplace<blob>(); val.emplace<blob_type_t>();
break; break;
default: default:
val.emplace<nullptr_t>(); val.emplace<nullptr_t>();

View File

@ -12,7 +12,7 @@ size_t determine_size(const char *val) {
return strlen(val); return strlen(val);
} }
size_t determine_size(const blob &val) { size_t determine_size(const blob_type_t &val) {
return val.size(); return val.size();
} }
} }

View File

@ -84,10 +84,6 @@ const class sql::dialect &session::dialect() const {
return dialect_; return dialect_;
} }
void session::dump_schema(std::ostream &os) const {
schema_.repo().dump(os);
}
utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> session::fetch(const sql::query_context& ctx) const { utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> session::fetch(const sql::query_context& ctx) const {
if (const auto result = cache_.acquire(ctx); !result) { if (const auto result = cache_.acquire(ctx); !result) {
return utils::failure(result.err()); return utils::failure(result.err());

View File

@ -77,7 +77,7 @@ void attribute_string_writer::write_value(size_t /*pos*/, const utils::time_type
result_ = "'" + dialect_.prepare_literal(utils::to_string(x)) + "'"; result_ = "'" + dialect_.prepare_literal(utils::to_string(x)) + "'";
} }
void attribute_string_writer::write_value(size_t /*pos*/, const utils::timestamp &/*x*/) { void attribute_string_writer::write_value(size_t /*pos*/, const utils::timestamp_type_t &/*x*/) {
} }
void attribute_string_writer::write_value(size_t pos, const char *x) { void attribute_string_writer::write_value(size_t pos, const char *x) {
@ -96,7 +96,7 @@ void attribute_string_writer::write_value(size_t /*pos*/, const std::string &x,
result_ = "'" + dialect_.prepare_literal(x) + "'"; result_ = "'" + dialect_.prepare_literal(x) + "'";
} }
void attribute_string_writer::write_value(size_t /*pos*/, const utils::blob &x) { void attribute_string_writer::write_value(size_t /*pos*/, const utils::blob_type_t &x) {
// "This is a binary Data string" as binary data: // "This is a binary Data string" as binary data:
// MySQL: X'5468697320697320612062616E617279204461746120737472696E67' // MySQL: X'5468697320697320612062616E617279204461746120737472696E67'
// Postgres: '\\x5468697320697320612062616E617279204461746120737472696E67' // Postgres: '\\x5468697320697320612062616E617279204461746120737472696E67'

View File

@ -342,8 +342,8 @@ void query_compiler::visit(internal::query_create_table_constraints_part& part)
} }
void query_compiler::visit( internal::query_create_schema_part& part ) { void query_compiler::visit( internal::query_create_schema_part& part ) {
query_.sql += " " + dialect_->create() + " " + query_.command = sql::sql_command::SQL_CREATE_SCHEMA;
dialect_->schema() + " " + dialect_->prepare_identifier_string(part.schema()); query_.sql += " " + dialect_->schema() + " " + dialect_->prepare_identifier_string(part.schema());
} }
void query_compiler::visit(internal::query_drop_part &part) { void query_compiler::visit(internal::query_drop_part &part) {
@ -440,7 +440,7 @@ std::string query_compiler::build_table_name(const sql::dialect_token token, con
} }
std::string query_compiler::build_add_constraint_string(const table_constraint &c) const { std::string query_compiler::build_add_constraint_string(const table_constraint &c) const {
std::string result = dialect_->add_constraint() + " " + build_constraint_name(c) + " "; std::string result = " " + dialect_->add_constraint() + " " + build_constraint_name(c) + " ";
if (c.is_primary_key_constraint()) { if (c.is_primary_key_constraint()) {
result.append(dialect_->primary_key()).append(" (").append(c.column_name()).append(")"); result.append(dialect_->primary_key()).append(" (").append(c.column_name()).append(")");
} else if (c.is_foreign_key_constraint()) { } else if (c.is_foreign_key_constraint()) {

View File

@ -218,6 +218,13 @@ schema::const_iterator schema::find(const std::string &name) const {
return schema_nodes_.find(result->get().type_index()); return schema_nodes_.find(result->get().type_index());
} }
void schema::dump(std::ostream &os) const {
os << repo_.name() << std::endl;
for (const auto &node: repo_) {
os << " " << node.name() << std::endl;
}
}
sql::query_context schema::build_add_constraint_context(const object::repository_node &node, sql::query_context schema::build_add_constraint_context(const object::repository_node &node,
const object::restriction &cons, const object::restriction &cons,
const sql::connection &conn) const { const sql::connection &conn) const {

View File

@ -69,7 +69,7 @@ void value_extractor::write_value(size_t /*pos*/, const utils::time_type_t &x) {
values_.emplace_back(x); values_.emplace_back(x);
} }
void value_extractor::write_value(size_t /*pos*/, const utils::timestamp &x) { void value_extractor::write_value(size_t /*pos*/, const utils::timestamp_type_t &x) {
values_.emplace_back(x); values_.emplace_back(x);
} }
@ -89,7 +89,7 @@ void value_extractor::write_value(size_t /*pos*/, const std::string &x, size_t /
values_.emplace_back(x); values_.emplace_back(x);
} }
void value_extractor::write_value(size_t /*pos*/, const utils::blob &x) { void value_extractor::write_value(size_t /*pos*/, const utils::blob_type_t &x) {
values_.emplace_back(x); values_.emplace_back(x);
} }

View File

@ -97,7 +97,7 @@ std::string dialect::next_placeholder(const std::vector<std::string> &bind_vars)
return placeholder_func_(bind_vars.size()); return placeholder_func_(bind_vars.size());
} }
std::string dialect::to_escaped_string(const utils::blob &value, const connection_impl *conn) const { std::string dialect::to_escaped_string(const utils::blob_type_t &value, const connection_impl *conn) const {
if (conn != nullptr) { if (conn != nullptr) {
return conn->to_escaped_string(value); return conn->to_escaped_string(value);
} }

View File

@ -60,7 +60,7 @@ TEST_CASE_METHOD(QueryFixture, "Insert and select basic datatypes", "[query][dat
"gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
// matador::date date_val(15, 3, 2015); // matador::date date_val(15, 3, 2015);
// auto time_val = matador::time(2015, 3, 15, 13, 56, 23, 123); // auto time_val = matador::time(2015, 3, 15, 13, 56, 23, 123);
matador::utils::blob blob_val {1,2,3,4,5,6,7,8}; matador::utils::blob_type_t blob_val {1,2,3,4,5,6,7,8};
types t { types t {
1, 1,

View File

@ -88,7 +88,7 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
std::string varchar{"good day"}; std::string varchar{"good day"};
date_type_t md{2025, 11, 27}; date_type_t md{2025, 11, 27};
time_type_t mt{12, 34, 56}; time_type_t mt{12, 34, 56};
blob bin{0x01,0x02,0x03,0x04}; blob_type_t bin{0x01,0x02,0x03,0x04};
res = query::insert() res = query::insert()
.into("types", cols) .into("types", cols)
@ -122,7 +122,7 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
REQUIRE(md == row.at<date_type_t>("val_date")); REQUIRE(md == row.at<date_type_t>("val_date"));
const auto mtres = row.at<time_type_t>("val_time"); const auto mtres = row.at<time_type_t>("val_time");
REQUIRE(mt == row.at<time_type_t>("val_time")); REQUIRE(mt == row.at<time_type_t>("val_time"));
REQUIRE(bin == row.at<blob>("val_blob")); REQUIRE(bin == row.at<blob_type_t>("val_blob"));
} }
TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][record]") TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][record]")

View File

@ -84,7 +84,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
REQUIRE((*row)->id == 1); REQUIRE((*row)->id == 1);
REQUIRE((*row)->name == "george"); REQUIRE((*row)->name == "george");
REQUIRE((*row)->age == 45); REQUIRE((*row)->age == 45);
REQUIRE((*row)->image == matador::utils::blob{1,2,3,4}); REQUIRE((*row)->image == matador::utils::blob_type_t{1,2,3,4});
} }
TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][update]") { TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][update]") {
@ -129,7 +129,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE((*row)->id == 1); REQUIRE((*row)->id == 1);
REQUIRE((*row)->name == "george"); REQUIRE((*row)->name == "george");
REQUIRE((*row)->age == 45); REQUIRE((*row)->age == 45);
REQUIRE((*row)->image == blob{1,2,3,4}); REQUIRE((*row)->image == blob_type_t{1,2,3,4});
george.age = 36; george.age = 36;
george.image = {5,6,7,8}; george.image = {5,6,7,8};
@ -154,7 +154,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE((*row)->id == 1); REQUIRE((*row)->id == 1);
REQUIRE((*row)->name == "george"); REQUIRE((*row)->name == "george");
REQUIRE((*row)->age == 36); REQUIRE((*row)->age == 36);
REQUIRE((*row)->image == blob{5,6,7,8}); REQUIRE((*row)->image == blob_type_t{5,6,7,8});
} }
TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][delete]") { TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][delete]") {

View File

@ -118,8 +118,8 @@ TEST_CASE("Test string to floating point conversion", "[convert][string][floatin
} }
TEST_CASE("Test blob to blob conversion", "[convert][blob]") { TEST_CASE("Test blob to blob conversion", "[convert][blob]") {
blob from{1, 2, 3, 4}; blob_type_t from{1, 2, 3, 4};
const auto res = to<blob>(from); const auto res = to<blob_type_t>(from);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(from == *res); REQUIRE(from == *res);

View File

@ -24,5 +24,5 @@ TEST_CASE("Test default data types", "[data_types][type]") {
REQUIRE(data_type_traits<char[]>::type(0) == basic_type::Text); REQUIRE(data_type_traits<char[]>::type(0) == basic_type::Text);
REQUIRE(data_type_traits<std::string>::type(32) == basic_type::Varchar); REQUIRE(data_type_traits<std::string>::type(32) == basic_type::Varchar);
REQUIRE(data_type_traits<std::string>::type(0) == basic_type::Text); REQUIRE(data_type_traits<std::string>::type(0) == basic_type::Text);
REQUIRE(data_type_traits<blob>::type(0) == basic_type::Blob); REQUIRE(data_type_traits<blob_type_t>::type(0) == basic_type::Blob);
} }

View File

@ -13,7 +13,7 @@ struct person {
unsigned int id{}; unsigned int id{};
std::string name; std::string name;
unsigned int age{}; unsigned int age{};
utils::blob image{}; utils::blob_type_t image{};
template<class Operator> template<class Operator>
void process(Operator &op) { void process(Operator &op) {

View File

@ -27,7 +27,7 @@ struct types
std::string varchar_ = "Erde"; std::string varchar_ = "Erde";
// matador::date date_; // matador::date date_;
// matador::time time_; // matador::time time_;
utils::blob binary_{ 1, 2, 3, 4 }; utils::blob_type_t binary_{ 1, 2, 3, 4 };
template < class Operator > template < class Operator >
void process(Operator &op) void process(Operator &op)

View File

@ -65,7 +65,7 @@ utils::result<bool, utils::error> test_connection::exists(const std::string &/*s
return utils::ok(false); return utils::ok(false);
} }
std::string test_connection::to_escaped_string(const utils::blob& value) const { std::string test_connection::to_escaped_string(const utils::blob_type_t& value) const {
return utils::to_string(value); return utils::to_string(value);
} }

View File

@ -22,7 +22,7 @@ public:
utils::result<std::vector<object::attribute>, utils::error> describe(const std::string &table) override; utils::result<std::vector<object::attribute>, utils::error> describe(const std::string &table) override;
utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override; utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override;
[[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override; [[nodiscard]] std::string to_escaped_string( const utils::blob_type_t& value ) const override;
private: private:
bool is_open_{false}; bool is_open_{false};

View File

@ -14,11 +14,11 @@ void test_parameter_binder::write_value(size_t /*pos*/, const float &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const double &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const double &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const utils::date_type_t &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::date_type_t &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const utils::time_type_t &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::time_type_t &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const utils::timestamp &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::timestamp_type_t &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/, size_t /*size*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const char * /*x*/, size_t /*size*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/, size_t /*size*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const std::string &/*x*/, size_t /*size*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const utils::blob &/*x*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::blob_type_t &/*x*/) {}
void test_parameter_binder::write_value(size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {} void test_parameter_binder::write_value(size_t /*pos*/, const utils::value &/*x*/, size_t /*size*/) {}
} }

View File

@ -20,12 +20,12 @@ public:
void write_value(size_t pos, const double &x) override; void write_value(size_t pos, const double &x) override;
void write_value(size_t pos, const utils::date_type_t &x) override; void write_value(size_t pos, const utils::date_type_t &x) override;
void write_value(size_t pos, const utils::time_type_t &x) override; void write_value(size_t pos, const utils::time_type_t &x) override;
void write_value(size_t pos, const utils::timestamp &x) override; void write_value(size_t pos, const utils::timestamp_type_t &x) override;
void write_value(size_t pos, const char *x) override; void write_value(size_t pos, const char *x) override;
void write_value(size_t pos, const char *x, size_t size) override; void write_value(size_t pos, const char *x, size_t size) override;
void write_value(size_t pos, const std::string &x) override; void write_value(size_t pos, const std::string &x) override;
void write_value(size_t pos, const std::string &x, size_t size) override; void write_value(size_t pos, const std::string &x, size_t size) override;
void write_value(size_t pos, const utils::blob &x) override; void write_value(size_t pos, const utils::blob_type_t &x) override;
void write_value(size_t pos, const utils::value &x, size_t size) override; void write_value(size_t pos, const utils::value &x, size_t size) override;
}; };

View File

@ -64,10 +64,16 @@ void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/,
value = 2.14159265358979323846; value = 2.14159265358979323846;
} }
void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, matador::time &/*value*/) { void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, utils::date_type_t &value) {
value = {2021, 10, 27};
} }
void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, matador::date &/*value*/) { void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, utils::time_type_t &value) {
value = {12, 34, 56, 123456};
}
void test_result_reader::read_value(const char *id, size_t index, utils::timestamp_type_t &value) {
value = utils::timestamp_type_t();
} }
void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, char * /*value*/, const size_t /*size*/) { void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, char * /*value*/, const size_t /*size*/) {
@ -81,7 +87,7 @@ void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/,
value = "Hello world"; value = "Hello world";
} }
void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, utils::blob &value) { void test_result_reader::read_value(const char * /*id*/, const size_t /*index*/, utils::blob_type_t &value) {
value = {'b', 'l', 'o', 'b'}; value = {'b', 'l', 'o', 'b'};
} }

View File

@ -21,12 +21,13 @@ public:
void read_value(const char *, size_t, bool &) override {} void read_value(const char *, size_t, bool &) override {}
void read_value(const char *, size_t, float &) override {} void read_value(const char *, size_t, float &) override {}
void read_value(const char *, size_t, double &) override {} void read_value(const char *, size_t, double &) override {}
void read_value(const char *, size_t, time &) override {} void read_value(const char *, size_t, utils::date_type_t &) override {}
void read_value(const char *, size_t, date &) override {} void read_value(const char *, size_t, utils::time_type_t &) override {}
void read_value(const char *, size_t, utils::timestamp_type_t &) override {}
void read_value(const char *, size_t, char *, size_t) override {} void read_value(const char *, size_t, char *, size_t) override {}
void read_value(const char *, size_t, std::string &) override {} void read_value(const char *, size_t, std::string &) override {}
void read_value(const char *, size_t, std::string &, size_t) override {} void read_value(const char *, size_t, std::string &, size_t) override {}
void read_value(const char *, size_t, utils::blob &) override {} void read_value(const char *, size_t, utils::blob_type_t &) override {}
void read_value(const char *, size_t, utils::value &, size_t) override {} void read_value(const char *, size_t, utils::value &, size_t) override {}
}; };
@ -51,12 +52,13 @@ public:
void read_value(const char *id, size_t index, bool &value) override; void read_value(const char *id, size_t index, bool &value) override;
void read_value(const char *id, size_t index, float &value) override; void read_value(const char *id, size_t index, float &value) override;
void read_value(const char *id, size_t index, double &value) override; void read_value(const char *id, size_t index, double &value) override;
void read_value(const char *id, size_t index, matador::time &value) override; void read_value(const char *id, size_t index, utils::date_type_t &value) override;
void read_value(const char *id, size_t index, matador::date &value) override; void read_value(const char *id, size_t index, utils::time_type_t &value) override;
void read_value(const char *id, size_t index, utils::timestamp_type_t &value) override;
void read_value(const char *id, size_t index, char *value, size_t size) override; void read_value(const char *id, size_t index, char *value, size_t size) override;
void read_value(const char *id, size_t index, std::string &value) override; void read_value(const char *id, size_t index, std::string &value) override;
void read_value(const char *id, size_t index, std::string &value, size_t size) override; void read_value(const char *id, size_t index, std::string &value, size_t size) override;
void read_value(const char *id, size_t index, utils::blob &value) override; void read_value(const char *id, size_t index, utils::blob_type_t &value) override;
void read_value(const char *id, size_t index, utils::value &val, size_t size) override; void read_value(const char *id, size_t index, utils::value &val, size_t size) override;
protected: protected:

View File

@ -234,7 +234,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
result = query::insert() result = query::insert()
.into("person", {"id", "name", "data"}) .into("person", {"id", "name", "data"})
.values({7U, "george", blob{1, 'A', 3, 4}}) .values({7U, "george", blob_type_t{1, 'A', 3, 4}})
.str(*db); .str(*db);
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "data") VALUES (7, 'george', X'01410304'))"); REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "data") VALUES (7, 'george', X'01410304'))");

View File

@ -37,7 +37,7 @@ TEST_CASE("Test field", "[field]") {
REQUIRE(bool_val.has_value()); REQUIRE(bool_val.has_value());
REQUIRE(bool_val.value()); REQUIRE(bool_val.value());
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, utils::constraints::None, 0, 1); f = sql::field("name", utils::blob_type_t{ 7,8,6,5,4,3 }, utils::constraints::None, 0, 1);
REQUIRE(f.index() == 1); REQUIRE(f.index() == 1);
REQUIRE(!f.is_null()); REQUIRE(!f.is_null());
REQUIRE(!f.is_integer()); REQUIRE(!f.is_integer());
@ -46,9 +46,9 @@ TEST_CASE("Test field", "[field]") {
REQUIRE(!f.is_bool()); REQUIRE(!f.is_bool());
REQUIRE(!f.is_string()); REQUIRE(!f.is_string());
auto blob_val = f.as<utils::blob>(); auto blob_val = f.as<utils::blob_type_t>();
REQUIRE(blob_val.has_value()); REQUIRE(blob_val.has_value());
REQUIRE(blob_val.value() == utils::blob{ 7,8,6,5,4,3 }); REQUIRE(blob_val.value() == utils::blob_type_t{ 7,8,6,5,4,3 });
REQUIRE(!f.as<std::string>().has_value()); REQUIRE(!f.as<std::string>().has_value());
} }