renamed schema to repository

This commit is contained in:
Sascha Kühl 2025-08-28 16:12:26 +02:00
parent cce7f2c099
commit 3ae2b003aa
45 changed files with 823 additions and 823 deletions

View File

@ -5,7 +5,7 @@
#include "matador/query/condition.hpp" #include "matador/query/condition.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/utils/access.hpp" #include "matador/utils/access.hpp"
#include "matador/utils/default_type_traits.hpp" #include "matador/utils/default_type_traits.hpp"
@ -161,7 +161,7 @@ int main() {
const std::string env_var{"MATADOR_BACKENDS_PATH"}; const std::string env_var{"MATADOR_BACKENDS_PATH"};
std::string dns{"sqlite://demo.db"}; std::string dns{"sqlite://demo.db"};
schema s( "main" ); repository s( "main" );
auto result = s.attach<author>( "authors" ).and_then( [&s] { auto result = s.attach<author>( "authors" ).and_then( [&s] {
return s.attach<book>( "books" ); return s.attach<book>( "books" );
} ); } );

View File

@ -1,4 +1,4 @@
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/logger/log_manager.hpp" #include "matador/logger/log_manager.hpp"
@ -133,82 +133,82 @@ int main() {
{ {
// has_many with builtin-type // has_many with builtin-type
object::schema schema; object::repository repo;
auto result = schema.attach<names>("names"); auto result = repo.attach<names>("names");
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_many with foreign without belongs_to // has_many with foreign without belongs_to
object::schema schema; object::repository repo;
auto result = schema.attach<person_repo>("person_repo") auto result = repo.attach<person_repo>("person_repo")
.and_then([&schema] { return schema.attach<person>("persons"); }); .and_then([&repo] { return repo.attach<person>("persons"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_many with foreign without belongs_to // has_many with foreign without belongs_to
object::schema schema; object::repository repo;
auto result = schema.attach<person>("persons") auto result = repo.attach<person>("persons")
.and_then([&schema] { return schema.attach<person_repo>("person_repo"); }); .and_then([&repo] { return repo.attach<person_repo>("person_repo"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_many to belongs_to // has_many to belongs_to
object::schema schema; object::repository repo;
auto result = schema.attach<author>("authors") auto result = repo.attach<author>("authors")
.and_then([&schema] { return schema.attach<book>("books"); }); .and_then([&repo] { return repo.attach<book>("books"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// belongs_to to has_many // belongs_to to has_many
object::schema schema; object::repository repo;
auto result = schema.attach<book>("books") auto result = repo.attach<book>("books")
.and_then([&schema] { return schema.attach<author>("authors"); }); .and_then([&repo] { return repo.attach<author>("authors"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_many_to_many (with join columns first) // has_many_to_many (with join columns first)
object::schema schema; object::repository repo;
auto result = schema.attach<demo::ingredient>("ingredients") auto result = repo.attach<demo::ingredient>("ingredients")
.and_then([&schema] { return schema.attach<recipe>("recipes"); }); .and_then([&repo] { return repo.attach<recipe>("recipes"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_many_to_many (with join columns last) // has_many_to_many (with join columns last)
object::schema schema; object::repository repo;
auto result = schema.attach<demo::recipe>("recipes") auto result = repo.attach<demo::recipe>("recipes")
.and_then([&schema] { return schema.attach<ingredient>("ingredients"); }); .and_then([&repo] { return repo.attach<ingredient>("ingredients"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// belongs_to to has_one // belongs_to to has_one
object::schema schema; object::repository repo;
auto result = schema.attach<profile>("profiles") auto result = repo.attach<profile>("profiles")
.and_then([&schema] { return schema.attach<user>("users"); }); .and_then([&repo] { return repo.attach<user>("users"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
{ {
// has_one to belongs_to // has_one to belongs_to
object::schema schema; object::repository repo;
auto result = schema.attach<user>("users") auto result = repo.attach<user>("users")
.and_then([&schema] { return schema.attach<profile>("profiles"); }); .and_then([&repo] { return repo.attach<profile>("profiles"); });
schema.dump(std::cout); repo.dump(std::cout);
} }
} }

View File

@ -17,7 +17,7 @@
#include "work/jobs/IdListPayload.hpp" #include "work/jobs/IdListPayload.hpp"
#include "matador/utils/default_type_traits.hpp" #include "matador/utils/default_type_traits.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
@ -76,11 +76,11 @@ int main() {
// 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::schema admin_schema("Administration"); object::repository repo("Administration");
auto result = admin_schema.attach<admin::CollectionCenter>("collection_centers"); auto result = repo.attach<admin::CollectionCenter>("collection_centers");
admin_schema.create(pool); repo.create(pool);
admin_schema.drop(pool); repo.drop(pool);
orm::session ses(pool); orm::session ses(pool);

View File

@ -16,7 +16,7 @@
namespace matador::object { namespace matador::object {
class schema; class repository;
class fk_attribute_generator class fk_attribute_generator
{ {
@ -54,13 +54,13 @@ private:
class attribute_definition_generator final { class attribute_definition_generator final {
private: private:
attribute_definition_generator(std::vector<attribute_definition> &columns, const schema &repo); attribute_definition_generator(std::vector<attribute_definition> &columns, const repository &repo);
public: public:
~attribute_definition_generator() = default; ~attribute_definition_generator() = default;
template < class Type > template < class Type >
static std::vector<attribute_definition> generate(const schema &repo) static std::vector<attribute_definition> generate(const repository &repo)
{ {
std::vector<attribute_definition> columns; std::vector<attribute_definition> columns;
attribute_definition_generator gen(columns, repo); attribute_definition_generator gen(columns, repo);
@ -70,7 +70,7 @@ public:
} }
template < class Type > template < class Type >
static std::vector<attribute_definition> generate(const Type& obj, const schema &repo) { static std::vector<attribute_definition> generate(const Type& obj, const repository &repo) {
std::vector<attribute_definition> columns; std::vector<attribute_definition> columns;
attribute_definition_generator gen(columns, repo); attribute_definition_generator gen(columns, repo);
access::process(gen, obj); access::process(gen, obj);
@ -127,7 +127,7 @@ private:
private: private:
size_t index_ = 0; size_t index_ = 0;
std::vector<attribute_definition> &columns_; std::vector<attribute_definition> &columns_;
const schema &repo_; const repository &repo_;
fk_attribute_generator fk_column_generator_; fk_attribute_generator fk_column_generator_;
}; };

View File

@ -11,7 +11,7 @@
namespace matador::object { namespace matador::object {
class schema_node; class repository_node;
class relation_endpoint; class relation_endpoint;
class basic_object_info { class basic_object_info {
@ -49,12 +49,12 @@ public:
[[nodiscard]] bool endpoints_empty() const; [[nodiscard]] bool endpoints_empty() const;
protected: protected:
basic_object_info(std::shared_ptr<schema_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column, object_definition &&definition); basic_object_info(std::shared_ptr<repository_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column, object_definition &&definition);
basic_object_info(std::shared_ptr<schema_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column); basic_object_info(std::shared_ptr<repository_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column);
basic_object_info(std::shared_ptr<schema_node> node, object_definition &&definition); basic_object_info(std::shared_ptr<repository_node> node, object_definition &&definition);
protected: protected:
std::shared_ptr<schema_node> node_; /**< prototype node of the represented object type */ std::shared_ptr<repository_node> node_; /**< prototype node of the represented object type */
object_definition definition_; object_definition definition_;
std::optional<utils::identifier> identifier_; std::optional<utils::identifier> identifier_;
std::shared_ptr<attribute_definition> pk_column_; std::shared_ptr<attribute_definition> pk_column_;

View File

@ -1,8 +1,8 @@
#ifndef FOREIGN_NODE_COMPLETER_HPP #ifndef FOREIGN_NODE_COMPLETER_HPP
#define FOREIGN_NODE_COMPLETER_HPP #define FOREIGN_NODE_COMPLETER_HPP
#include "matador/object/internal/shadow_schema.hpp" #include "matador/object/internal/shadow_repository.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
#include "matador/object/join_columns_collector.hpp" #include "matador/object/join_columns_collector.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
@ -21,12 +21,12 @@ namespace matador::object {
*/ */
class foreign_node_completer final { class foreign_node_completer final {
private: private:
using node_ptr = std::shared_ptr<schema_node>; using node_ptr = std::shared_ptr<repository_node>;
public: public:
template<class Type> template<class Type>
static void complete(const std::shared_ptr<schema_node> &node) { static void complete(const std::shared_ptr<repository_node> &node) {
internal::shadow_schema shadow(node->schema_); internal::shadow_repository shadow(node->repo_);
foreign_node_completer completer(shadow); foreign_node_completer completer(shadow);
completer.complete_node<Type>(node); completer.complete_node<Type>(node);
@ -56,10 +56,10 @@ public:
void on_has_many_to_many(const char *id, CollectionType &collection, const utils::foreign_attributes &attr); void on_has_many_to_many(const char *id, CollectionType &collection, const utils::foreign_attributes &attr);
private: private:
explicit foreign_node_completer(internal::shadow_schema &shadow); explicit foreign_node_completer(internal::shadow_repository &shadow);
template<typename Type> template<typename Type>
void complete_node(const std::shared_ptr<schema_node> &node) { void complete_node(const std::shared_ptr<repository_node> &node) {
nodes_.push(node); nodes_.push(node);
Type obj; Type obj;
@ -69,17 +69,17 @@ private:
template<typename Type> template<typename Type>
void attach_node() { void attach_node() {
if (schema_.schema_contains(typeid(Type))) { if (repo_.contains(typeid(Type))) {
return; return;
} }
const auto node = schema_node::make_node<Type>(schema_.schema(), ""); const auto node = repository_node::make_node<Type>(repo_.repo(), "");
if (auto result = schema_.attach_node(node)) { if (auto result = repo_.attach_node(node)) {
complete<Type>(result.value()); complete<Type>(result.value());
} }
} }
private: private:
std::stack<node_ptr> nodes_; std::stack<node_ptr> nodes_;
internal::shadow_schema &schema_; internal::shadow_repository &repo_;
logger::logger log_; logger::logger log_;
join_columns_collector join_columns_collector_{}; join_columns_collector join_columns_collector_{};
}; };

View File

@ -8,27 +8,27 @@
#include <typeindex> #include <typeindex>
namespace matador::object { namespace matador::object {
class schema; class repository;
class schema_node; class repository_node;
} }
namespace matador::object::internal { namespace matador::object::internal {
class shadow_schema { class shadow_repository {
private: private:
using node_ptr = std::shared_ptr<schema_node>; using node_ptr = std::shared_ptr<repository_node>;
public: public:
explicit shadow_schema(object::schema& s); explicit shadow_repository(object::repository& s);
[[nodiscard]] object::schema& schema() const; [[nodiscard]] object::repository& repo() const;
[[nodiscard]] bool schema_contains(const std::type_index& ti) const; [[nodiscard]] bool contains(const std::type_index& ti) const;
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::type_index &type_index) const; [[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::type_index &type_index) const;
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::string &name) const; [[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::string &name) const;
[[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const std::shared_ptr<schema_node> &node) const; [[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const std::shared_ptr<repository_node> &node) const;
[[nodiscard]] utils::result<void, utils::error> detach_node(const std::shared_ptr<schema_node> &node) const; [[nodiscard]] utils::result<void, utils::error> detach_node(const std::shared_ptr<repository_node> &node) const;
private: private:
object::schema& schema_; object::repository& schema_;
}; };
} }
#endif //SHADOW_SCHEMA_HPP #endif //SHADOW_SCHEMA_HPP

View File

@ -5,26 +5,26 @@
#include "matador/object/object_definition.hpp" #include "matador/object/object_definition.hpp"
namespace matador::object { namespace matador::object {
class schema_node; class repository_node;
template<typename Type> template<typename Type>
class object_info final : public basic_object_info { class object_info final : public basic_object_info {
public: public:
using create_func = std::function<std::unique_ptr<Type>()>; using create_func = std::function<std::unique_ptr<Type>()>;
object_info(const std::shared_ptr<schema_node>& node, object_info(const std::shared_ptr<repository_node>& node,
const std::shared_ptr<attribute_definition> &ref_column) const std::shared_ptr<attribute_definition> &ref_column)
: basic_object_info(node, {}, ref_column, {}) : basic_object_info(node, {}, ref_column, {})
, creator_([]{return std::make_unique<Type>(); }){ , creator_([]{return std::make_unique<Type>(); }){
} }
object_info(const std::shared_ptr<schema_node>& node, object_info(const std::shared_ptr<repository_node>& node,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &ref_column, const std::shared_ptr<attribute_definition> &ref_column,
object_definition &&definition) object_definition &&definition)
: basic_object_info(node, std::move(pk), ref_column, std::move(definition)) : basic_object_info(node, std::move(pk), ref_column, std::move(definition))
, creator_([]{return std::make_unique<Type>(); }){ , creator_([]{return std::make_unique<Type>(); }){
} }
object_info(const std::shared_ptr<schema_node>& node, object_info(const std::shared_ptr<repository_node>& node,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &ref_column, const std::shared_ptr<attribute_definition> &ref_column,
object_definition &&definition, object_definition &&definition,
@ -32,7 +32,7 @@ public:
: basic_object_info(node, std::move(pk), ref_column, std::move(definition)) : basic_object_info(node, std::move(pk), ref_column, std::move(definition))
, creator_(std::move(creator)){ , creator_(std::move(creator)){
} }
object_info(const std::shared_ptr<schema_node>& node, object_info(const std::shared_ptr<repository_node>& node,
object_definition &&definition, object_definition &&definition,
create_func&& creator) create_func&& creator)
: basic_object_info(node, std::move(definition)) : basic_object_info(node, std::move(definition))

View File

@ -1,11 +1,11 @@
#ifndef RELATION_COMPLETER_HPP #ifndef RELATION_COMPLETER_HPP
#define RELATION_COMPLETER_HPP #define RELATION_COMPLETER_HPP
#include "matador/object/internal/shadow_schema.hpp" #include "matador/object/internal/shadow_repository.hpp"
#include "matador/object/many_to_many_relation.hpp" #include "matador/object/many_to_many_relation.hpp"
#include "matador/object/join_columns_collector.hpp" #include "matador/object/join_columns_collector.hpp"
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
#include "matador/logger/log_manager.hpp" #include "matador/logger/log_manager.hpp"
@ -94,13 +94,13 @@ private:
template<typename Type> template<typename Type>
class relation_completer final { class relation_completer final {
private: private:
using node_ptr = std::shared_ptr<schema_node>; using node_ptr = std::shared_ptr<repository_node>;
public: public:
using endpoint_ptr = std::shared_ptr<relation_endpoint>; using endpoint_ptr = std::shared_ptr<relation_endpoint>;
static void complete(const std::shared_ptr<schema_node> &node) { static void complete(const std::shared_ptr<repository_node> &node) {
internal::shadow_schema shadow(node->schema_); internal::shadow_repository shadow(node->repo_);
relation_completer completer(shadow); relation_completer completer(shadow);
completer.complete_node_relations(node); completer.complete_node_relations(node);
@ -130,12 +130,12 @@ public:
void on_has_many_to_many(const char *id, CollectionType &collection, const utils::foreign_attributes &attr); void on_has_many_to_many(const char *id, CollectionType &collection, const utils::foreign_attributes &attr);
private: private:
explicit relation_completer(internal::shadow_schema &shadow) explicit relation_completer(internal::shadow_repository &shadow)
: schema_(shadow) : schema_(shadow)
, log_(logger::create_logger("relation_completer")) { , log_(logger::create_logger("relation_completer")) {
} }
void complete_node_relations(const std::shared_ptr<schema_node> &node) { void complete_node_relations(const std::shared_ptr<repository_node> &node) {
nodes_.push(node); nodes_.push(node);
Type obj; Type obj;
@ -150,7 +150,7 @@ private:
private: private:
std::stack<node_ptr> nodes_; std::stack<node_ptr> nodes_;
internal::shadow_schema &schema_; internal::shadow_repository &schema_;
logger::logger log_; logger::logger log_;
join_columns_collector join_columns_collector_{}; join_columns_collector join_columns_collector_{};
}; };
@ -192,8 +192,8 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
// belongs-to relation handles this relation, the many-to-many // belongs-to relation handles this relation, the many-to-many
// relation is maybe detached. // relation is maybe detached.
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column); log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column);
result = schema_node::make_relation_node<relation_value_type>( result = repository_node::make_relation_node<relation_value_type>(
schema_.schema(), id, [join_column] { schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>("id", join_column); return std::make_unique<relation_value_type>("id", join_column);
}); });
if (!result) { if (!result) {
@ -220,8 +220,8 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &, con
using value_type = typename CollectionType::value_type; using value_type = typename CollectionType::value_type;
using relation_value_type = many_to_relation<Type, value_type>; using relation_value_type = many_to_relation<Type, value_type>;
const auto result = schema_node::make_relation_node<relation_value_type>( const auto result = repository_node::make_relation_node<relation_value_type>(
schema_.schema(), id, [join_column] { schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>(join_column, "value"); return std::make_unique<relation_value_type>(join_column, "value");
}); });
@ -263,7 +263,7 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
return std::make_unique<relation_value_type>(join_column, inverse_join_column); return std::make_unique<relation_value_type>(join_column, inverse_join_column);
}; };
result = schema_node::make_relation_node<relation_value_type>(schema_.schema(), id, std::move(creator)); result = repository_node::make_relation_node<relation_value_type>(schema_.repo(), id, std::move(creator));
if (!result) { if (!result) {
// Todo: throw internal error // Todo: throw internal error
return; return;

View File

@ -8,7 +8,7 @@
namespace matador::object { namespace matador::object {
class schema_node; class repository_node;
enum class relation_type : uint8_t { enum class relation_type : uint8_t {
BELONGS_TO, BELONGS_TO,
@ -24,14 +24,14 @@ static const utils::enum_mapper<relation_type> relation_type_enum({
class relation_endpoint { class relation_endpoint {
public: public:
relation_endpoint(std::string field_name, relation_type type, const std::shared_ptr<schema_node>& node); relation_endpoint(std::string field_name, relation_type type, const std::shared_ptr<repository_node>& node);
[[nodiscard]] std::string field_name() const; [[nodiscard]] std::string field_name() const;
[[nodiscard]] relation_type type() const; [[nodiscard]] relation_type type() const;
[[nodiscard]] std::string type_name() const; [[nodiscard]] std::string type_name() const;
[[nodiscard]] const schema_node& node() const; [[nodiscard]] const repository_node& node() const;
[[nodiscard]] std::shared_ptr<schema_node> node_ptr() const; [[nodiscard]] std::shared_ptr<repository_node> node_ptr() const;
[[nodiscard]] bool is_has_one() const; [[nodiscard]] bool is_has_one() const;
[[nodiscard]] bool is_has_many() const; [[nodiscard]] bool is_has_many() const;
@ -46,7 +46,7 @@ private:
std::string field_name_; std::string field_name_;
relation_type type_; relation_type type_;
std::shared_ptr<schema_node> node_; std::shared_ptr<repository_node> node_;
std::shared_ptr<relation_endpoint> foreign_endpoint_; std::shared_ptr<relation_endpoint> foreign_endpoint_;
}; };

View File

@ -1,190 +1,190 @@
#ifndef SCHEMA_HPP #ifndef SCHEMA_HPP
#define SCHEMA_HPP #define SCHEMA_HPP
#include "matador/logger/log_manager.hpp" #include "matador/logger/log_manager.hpp"
#include "matador/object/error_code.hpp" #include "matador/object/error_code.hpp"
#include "matador/object/foreign_node_completer.hpp" #include "matador/object/foreign_node_completer.hpp"
#include "matador/object/relation_completer.hpp" #include "matador/object/relation_completer.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
#include "matador/object/schema_node_iterator.hpp" #include "matador/object/repository_node_iterator.hpp"
#include "matador/utils/result.hpp" #include "matador/utils/result.hpp"
#include "matador/utils/error.hpp" #include "matador/utils/error.hpp"
#include "matador/logger/logger.hpp" #include "matador/logger/logger.hpp"
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
namespace matador::object { namespace matador::object {
namespace internal { namespace internal {
class shadow_schema; class shadow_repository;
} }
utils::error make_error(error_code ec, const std::string &msg); utils::error make_error(error_code ec, const std::string &msg);
class schema { class repository {
public: public:
typedef const_schema_node_iterator const_iterator; /**< Shortcut for the list const iterator. */ typedef const_repository_node_iterator const_iterator; /**< Shortcut for the list const iterator. */
using node_ptr = std::shared_ptr<schema_node>; using node_ptr = std::shared_ptr<repository_node>;
/** /**
* Creates an empty schema * Creates an empty schema
*/ */
explicit schema(std::string name = ""); explicit repository(std::string name = "");
template<typename Type> template<typename Type>
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name, const std::string &parent = "") { [[nodiscard]] utils::result<void, utils::error> attach(const std::string &name, const std::string &parent = "") {
if (const auto it = nodes_by_type_.find(typeid(Type)); it == nodes_by_type_.end() ) { if (const auto it = nodes_by_type_.find(typeid(Type)); it == nodes_by_type_.end() ) {
// if the type was not found // if the type was not found
auto node = schema_node::make_node<Type>(*this, name); auto node = repository_node::make_node<Type>(*this, name);
if (auto result = attach_node(node, parent); !result) { if (auto result = attach_node(node, parent); !result) {
return utils::failure(result.err()); return utils::failure(result.err());
} }
foreign_node_completer::complete<Type>(node); foreign_node_completer::complete<Type>(node);
relation_completer<Type>::complete(node); relation_completer<Type>::complete(node);
} else if (!has_node(name)) { } else if (!has_node(name)) {
it->second->update_name(name); it->second->update_name(name);
nodes_by_name_[name] = it->second; nodes_by_name_[name] = it->second;
relation_completer<Type>::complete(it->second); relation_completer<Type>::complete(it->second);
log_.info("attach: update node name to '%s' (type: %s)", it->second->name().c_str(), it->second->type_index().name()); log_.info("attach: update node name to '%s' (type: %s)", it->second->name().c_str(), it->second->type_index().name());
} else { } else {
// remove_node( ) // remove_node( )
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists")); return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + name + "' already exists"));
} }
return utils::ok<void>(); return utils::ok<void>();
} }
template<typename Type, typename SuperType> template<typename Type, typename SuperType>
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name) { [[nodiscard]] utils::result<void, utils::error> attach(const std::string &name) {
const auto ti = std::type_index(typeid(SuperType)); const auto ti = std::type_index(typeid(SuperType));
auto result = find_node(ti); auto result = find_node(ti);
if (!result) { if (!result) {
return utils::failure(make_error(error_code::NodeNotFound, "Parent node '" + std::string(ti.name()) + "' not found")); return utils::failure(make_error(error_code::NodeNotFound, "Parent node '" + std::string(ti.name()) + "' not found"));
} }
return attach<Type>(name, (*result)->name()); return attach<Type>(name, (*result)->name());
} }
/** /**
* Detaches a given node from the schema. If the * Detaches a given node from the schema. If the
* node is a parent of other nodes, these nodes are * node is a parent of other nodes, these nodes are
* detached as well. * detached as well.
* *
* @param node Node to detach from schema * @param node Node to detach from schema
* @return Result object indicating success or failure * @return Result object indicating success or failure
*/ */
[[nodiscard]] utils::result<void, utils::error> detach(const node_ptr &node); [[nodiscard]] utils::result<void, utils::error> detach(const node_ptr &node);
/** /**
* Return the first schema node. * Return the first schema node.
* *
* @return The first schema node iterator. * @return The first schema node iterator.
*/ */
[[nodiscard]] const_iterator begin() const; [[nodiscard]] const_iterator begin() const;
/** /**
* Return the last schema node. * Return the last schema node.
* *
* @return The last schema node iterator. * @return The last schema node iterator.
*/ */
[[nodiscard]] const_iterator end() const; [[nodiscard]] const_iterator end() const;
/** /**
* Returns true if the schema contains * Returns true if the schema contains
* no schema nodes. * no schema nodes.
* *
* @return True if the schema is empty * @return True if the schema is empty
*/ */
[[nodiscard]] bool empty() const; [[nodiscard]] bool empty() const;
/** /**
* Returns the current number of the schema node. * Returns the current number of the schema node.
* *
* @return Number of schema nodes * @return Number of schema nodes
*/ */
[[nodiscard]] size_t size() const; [[nodiscard]] size_t size() const;
/** /**
* Returns the name of the schema. * Returns the name of the schema.
* *
* @return The name of the schema * @return The name of the schema
*/ */
[[nodiscard]] std::string name() const; [[nodiscard]] std::string name() const;
[[nodiscard]] bool contains(const std::string &name) const; [[nodiscard]] bool contains(const std::string &name) const;
[[nodiscard]] bool contains(const std::type_index &index) const; [[nodiscard]] bool contains(const std::type_index &index) const;
template < typename Type > template < typename Type >
[[nodiscard]] bool contains() const { [[nodiscard]] bool contains() const {
return contains(std::type_index(typeid(Type))); return contains(std::type_index(typeid(Type)));
} }
template<typename Type> template<typename Type>
[[nodiscard]] utils::result<object_info_ref<Type>, utils::error> info() const { [[nodiscard]] utils::result<object_info_ref<Type>, utils::error> info() const {
auto result = find_node(std::type_index(typeid(Type))); auto result = find_node(std::type_index(typeid(Type)));
if (!result) { if (!result) {
return utils::failure(result.err()); return utils::failure(result.err());
} }
return utils::ok(result.value()->info<Type>()); return utils::ok(result.value()->info<Type>());
} }
template<typename Type> template<typename Type>
[[nodiscard]] utils::result<basic_object_info_ref, utils::error> basic_info() const { [[nodiscard]] utils::result<basic_object_info_ref, utils::error> basic_info() const {
auto result = find_node(std::type_index(typeid(Type))); auto result = find_node(std::type_index(typeid(Type)));
if (!result) { if (!result) {
return utils::failure(result.err()); return utils::failure(result.err());
} }
return utils::ok(basic_object_info_ref{result.value()->info()}); return utils::ok(basic_object_info_ref{result.value()->info()});
} }
[[nodiscard]] utils::result<std::shared_ptr<attribute_definition>, utils::error> reference_column( [[nodiscard]] utils::result<std::shared_ptr<attribute_definition>, utils::error> reference_column(
const std::type_index &type_index) const; const std::type_index &type_index) const;
void dump(std::ostream &os) const; void dump(std::ostream &os) const;
static void dump(std::ostream &os, const node_ptr& node); static void dump(std::ostream &os, const node_ptr& node);
private: private:
using t_node_map = std::unordered_map<std::string, node_ptr>; using t_node_map = std::unordered_map<std::string, node_ptr>;
using t_type_index_node_map = std::unordered_map<std::type_index, node_ptr>; using t_type_index_node_map = std::unordered_map<std::type_index, node_ptr>;
[[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const node_ptr &node, const std::string &parent); [[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const node_ptr &node, const std::string &parent);
// [[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const node_ptr &node, const std::type_index &type_index); // [[nodiscard]] utils::result<node_ptr, utils::error> attach_node(const node_ptr &node, const std::type_index &type_index);
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::string &name) const; [[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::string &name) const;
[[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::type_index &type_index) const; [[nodiscard]] utils::result<node_ptr, utils::error> find_node(const std::type_index &type_index) const;
template<typename Type> template<typename Type>
[[nodiscard]] utils::result<node_ptr, utils::error> find_node() const { [[nodiscard]] utils::result<node_ptr, utils::error> find_node() const {
return find_node(std::type_index(typeid(Type))); return find_node(std::type_index(typeid(Type)));
} }
[[nodiscard]] bool has_node(const std::string &name) const; [[nodiscard]] bool has_node(const std::string &name) const;
[[nodiscard]] bool has_node(const std::type_index &index) const; [[nodiscard]] bool has_node(const std::type_index &index) const;
[[nodiscard]] bool has_node(const node_ptr& node) const; [[nodiscard]] bool has_node(const node_ptr& node) const;
static void insert_node(const node_ptr &parent, const node_ptr &child); static void insert_node(const node_ptr &parent, const node_ptr &child);
void remove_node(const node_ptr &node); void remove_node(const node_ptr &node);
private: private:
friend class internal::shadow_schema; friend class internal::shadow_repository;
friend class schema_node; friend class repository_node;
friend class attribute_definition_generator; friend class attribute_definition_generator;
std::string name_; std::string name_;
std::shared_ptr<schema_node> root_; std::shared_ptr<repository_node> root_;
t_node_map nodes_by_name_; t_node_map nodes_by_name_;
t_type_index_node_map nodes_by_type_; t_type_index_node_map nodes_by_type_;
logger::logger log_; logger::logger log_;
std::unordered_map<std::type_index, std::shared_ptr<attribute_definition> > missing_references_; std::unordered_map<std::type_index, std::shared_ptr<attribute_definition> > missing_references_;
}; };
} }
#endif //SCHEMA_HPP #endif //SCHEMA_HPP

View File

@ -10,15 +10,15 @@
namespace matador::object { namespace matador::object {
class basic_object_info; class basic_object_info;
class schema; class repository;
class schema_node final { class repository_node final {
public: public:
using node_ptr = std::shared_ptr<schema_node>; using node_ptr = std::shared_ptr<repository_node>;
template < typename Type > template < typename Type >
static std::shared_ptr<schema_node> make_node(object::schema& tree, const std::string& name) { static std::shared_ptr<repository_node> make_node(object::repository& tree, const std::string& name) {
auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, typeid(Type))); auto node = std::shared_ptr<repository_node>(new repository_node(tree, name, typeid(Type)));
primary_key_resolver resolver; primary_key_resolver resolver;
auto pk_info = resolver.resolve<Type>(); auto pk_info = resolver.resolve<Type>();
@ -36,7 +36,7 @@ public:
} }
template < typename Type, typename CreatorFunc > template < typename Type, typename CreatorFunc >
static utils::result<node_ptr, utils::error> make_relation_node(object::schema& tree, const std::string& name, CreatorFunc &&creator) { static utils::result<node_ptr, utils::error> make_relation_node(object::repository& tree, const std::string& name, CreatorFunc &&creator) {
const auto result = make_and_attach_node(tree, name, typeid(Type)); const auto result = make_and_attach_node(tree, name, typeid(Type));
if (!result) { if (!result) {
return result; return result;
@ -53,13 +53,13 @@ public:
return result; return result;
} }
static std::shared_ptr<schema_node> make_null_node(schema& tree); static std::shared_ptr<repository_node> make_null_node(repository& tree);
schema_node(const schema_node& other) = delete; repository_node(const repository_node& other) = delete;
schema_node(schema_node&& other) = default; repository_node(repository_node&& other) = default;
schema_node& operator=(const schema_node& other) = delete; repository_node& operator=(const repository_node& other) = delete;
schema_node& operator=(schema_node&& other) = delete; repository_node& operator=(repository_node&& other) = delete;
~schema_node() = default; ~repository_node() = default;
[[nodiscard]] std::string name() const; [[nodiscard]] std::string name() const;
[[nodiscard]] std::type_index type_index() const; [[nodiscard]] std::type_index type_index() const;
@ -76,39 +76,39 @@ public:
return std::ref(static_cast<const object_info<Type>&>(*info_)); return std::ref(static_cast<const object_info<Type>&>(*info_));
} }
[[nodiscard]] const object::schema& schema() const; [[nodiscard]] const object::repository& schema() const;
[[nodiscard]] bool has_children() const; [[nodiscard]] bool has_children() const;
private: private:
explicit schema_node(object::schema& tree); explicit repository_node(object::repository& tree);
schema_node(object::schema& tree, const std::type_index& ti); repository_node(object::repository& tree, const std::type_index& ti);
schema_node(object::schema& tree, std::string name, const std::type_index& ti); repository_node(object::repository& tree, std::string name, const std::type_index& ti);
void unlink(); void unlink();
static utils::result<node_ptr, utils::error> make_and_attach_node(object::schema& tree, const std::string& name, const std::type_index& ti); static utils::result<node_ptr, utils::error> make_and_attach_node(object::repository& tree, const std::string& name, const std::type_index& ti);
static std::shared_ptr<attribute_definition> determine_reference_column(const std::type_index& ti, static std::shared_ptr<attribute_definition> determine_reference_column(const std::type_index& ti,
const std::string& name, const std::string& name,
const primary_key_info& pk_info, const primary_key_info& pk_info,
object::schema& tree); object::repository& tree);
private: private:
friend class schema; friend class repository;
template<typename Type> template<typename Type>
friend class relation_completer; friend class relation_completer;
friend class foreign_node_completer; friend class foreign_node_completer;
friend class const_schema_node_iterator; friend class const_repository_node_iterator;
object::schema &schema_; object::repository &repo_;
std::type_index type_index_; std::type_index type_index_;
std::unique_ptr<basic_object_info> info_; std::unique_ptr<basic_object_info> info_;
std::shared_ptr<schema_node> parent_; std::shared_ptr<repository_node> parent_;
std::shared_ptr<schema_node> previous_sibling_; std::shared_ptr<repository_node> previous_sibling_;
std::shared_ptr<schema_node> next_sibling_; std::shared_ptr<repository_node> next_sibling_;
std::shared_ptr<schema_node> first_child_; std::shared_ptr<repository_node> first_child_;
std::shared_ptr<schema_node> last_child_; std::shared_ptr<repository_node> last_child_;
std::string name_; std::string name_;
size_t depth_{0}; size_t depth_{0};

View File

@ -1,24 +1,24 @@
#ifndef SCHEMA_NODE_ITERATOR_HPP #ifndef SCHEMA_NODE_ITERATOR_HPP
#define SCHEMA_NODE_ITERATOR_HPP #define SCHEMA_NODE_ITERATOR_HPP
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
#include <iterator> #include <iterator>
namespace matador::object { namespace matador::object {
class const_schema_node_iterator { class const_repository_node_iterator {
public: public:
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using value_type = std::shared_ptr<schema_node>; using value_type = std::shared_ptr<repository_node>;
using pointer = schema_node*; using pointer = repository_node*;
using reference = value_type; using reference = value_type;
/** /**
* Creates an empty iterator * Creates an empty iterator
*/ */
const_schema_node_iterator() = default; const_repository_node_iterator() = default;
/** /**
* @brief Creates an iterator for a concrete type. * @brief Creates an iterator for a concrete type.
@ -28,14 +28,14 @@ public:
* *
* @param node The schema node of the object * @param node The schema node of the object
*/ */
explicit const_schema_node_iterator(const value_type& node); explicit const_repository_node_iterator(const value_type& node);
/** /**
* Copy from a given const_object_view_iterator. * Copy from a given const_object_view_iterator.
* *
* @param x The prototype_iterator to copy from. * @param x The prototype_iterator to copy from.
*/ */
const_schema_node_iterator(const const_schema_node_iterator &x) = default; const_repository_node_iterator(const const_repository_node_iterator &x) = default;
/** /**
* Assign from a given prototype_iterator. * Assign from a given prototype_iterator.
@ -43,59 +43,59 @@ public:
* @param x The prototype_iterator to assign from. * @param x The prototype_iterator to assign from.
* @return The assigned prototype_iterator. * @return The assigned prototype_iterator.
*/ */
const_schema_node_iterator& operator=(const const_schema_node_iterator &x) = default; const_repository_node_iterator& operator=(const const_repository_node_iterator &x) = default;
~const_schema_node_iterator() = default; ~const_repository_node_iterator() = default;
/** /**
* @brief Compares this with another iterators. * @brief Compares this with other iterators.
* *
* Compares this with another iterators. Returns true * Compares this with other iterators. Returns true
* if the iterators node prototype_type are the same. * if the iterators node prototype_type are the same.
* *
* @param i The iterator to compare with. * @param i The iterator to compare with.
* @return True if the iterators are the same. * @return True if the iterators are the same.
*/ */
bool operator==(const const_schema_node_iterator &i) const; bool operator==(const const_repository_node_iterator &i) const;
/** /**
* @brief Compares this with another iterators. * @brief Compares this with other iterators.
* *
* Compares this with another iterators. Returns true * Compares this with other iterators. Returns true
* if the iterators node prototype_node are not the same. * if the iterators node prototype_node are different.
* *
* @param i The iterator to compare with. * @param i The iterator to compare with.
* @return True if the iterators are not the same. * @return True if the iterators are different.
*/ */
bool operator!=(const const_schema_node_iterator &i) const; bool operator!=(const const_repository_node_iterator &i) const;
/** /**
* Pre increments the iterator * Pre-increments the iterator
* *
* @return Returns iterators successor. * @return Returns iterators successor.
*/ */
const_schema_node_iterator& operator++(); const_repository_node_iterator& operator++();
/** /**
* Post increments the iterator * Post increments the iterator
* *
* @return Returns iterator before incrementing. * @return Returns iterator before incrementing.
*/ */
const_schema_node_iterator operator++( int ); const_repository_node_iterator operator++( int );
/** /**
* Pre increments the iterator * Pre-increments the iterator
* *
* @return Returns iterators predecessor. * @return Returns iterators predecessor.
*/ */
const_schema_node_iterator& operator--(); const_repository_node_iterator& operator--();
/** /**
* Post decrements the iterator * Post decrements the iterator
* *
* @return Returns iterator before decrementing. * @return Returns iterator before decrementing.
*/ */
const_schema_node_iterator operator--(int); const_repository_node_iterator operator--(int);
/** /**
* Returns the pointer to the node. * Returns the pointer to the node.
@ -123,7 +123,7 @@ private:
void decrement(); void decrement();
private: private:
value_type node_; value_type node_{};
}; };
} }

View File

@ -15,7 +15,7 @@
#include "matador/object/object_ptr.hpp" #include "matador/object/object_ptr.hpp"
#include "matador/object/object_definition.hpp" #include "matador/object/object_definition.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include <unordered_map> #include <unordered_map>
@ -181,7 +181,7 @@ private:
mutable sql::statement_cache cache_; mutable sql::statement_cache cache_;
const sql::dialect &dialect_; const sql::dialect &dialect_;
std::unique_ptr<object::schema> schema_; std::unique_ptr<object::repository> schema_;
mutable std::unordered_map<std::string, object::object_definition> prototypes_; mutable std::unordered_map<std::string, object::object_definition> prototypes_;
}; };

View File

@ -6,7 +6,7 @@
#include "matador/query/condition.hpp" #include "matador/query/condition.hpp"
#include "matador/query/query_intermediates.hpp" #include "matador/query/query_intermediates.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/utils/cascade_type.hpp" #include "matador/utils/cascade_type.hpp"
#include "matador/utils/primary_key_attribute.hpp" #include "matador/utils/primary_key_attribute.hpp"
@ -38,7 +38,7 @@ private:
class session_insert_builder final { class session_insert_builder final {
public: public:
explicit session_insert_builder(const object::schema &scm) explicit session_insert_builder(const object::repository &scm)
: schema_(scm) { : schema_(scm) {
} }
@ -123,7 +123,7 @@ private:
std::stack<table_info> table_info_stack_; std::stack<table_info> table_info_stack_;
std::unordered_map<std::string, std::shared_ptr<sql::table> > processed_tables_; std::unordered_map<std::string, std::shared_ptr<sql::table> > processed_tables_;
const object::schema &schema_; const object::repository &schema_;
std::vector<entity_insert_data> entity_insert_data_; std::vector<entity_insert_data> entity_insert_data_;
}; };
} }

View File

@ -10,7 +10,7 @@
#include "matador/sql/statement.hpp" #include "matador/sql/statement.hpp"
#include "matador/object/join_columns_collector.hpp" #include "matador/object/join_columns_collector.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/utils/primary_key_attribute.hpp" #include "matador/utils/primary_key_attribute.hpp"
#include "matador/utils/result.hpp" #include "matador/utils/result.hpp"
@ -32,7 +32,7 @@ struct entity_query_data {
class session_query_builder final { class session_query_builder final {
public: public:
session_query_builder(const object::schema &scm, sql::executor &exec) session_query_builder(const object::repository &scm, sql::executor &exec)
: schema_(scm) : schema_(scm)
, executor_(exec){} , executor_(exec){}
@ -247,7 +247,7 @@ private:
std::stack<table_info> table_info_stack_; std::stack<table_info> table_info_stack_;
std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_; std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_;
const object::schema &schema_; const object::repository &schema_;
entity_query_data entity_query_data_; entity_query_data entity_query_data_;
unsigned int column_index{0}; unsigned int column_index{0};
unsigned int table_index{0}; unsigned int table_index{0};

View File

@ -17,7 +17,7 @@ public:
executable_query table(const sql::table &table, std::initializer_list<object::attribute_definition> columns); executable_query table(const sql::table &table, std::initializer_list<object::attribute_definition> columns);
executable_query table(const sql::table &table, const std::vector<object::attribute_definition> &columns); executable_query table(const sql::table &table, const std::vector<object::attribute_definition> &columns);
template<class Type> template<class Type>
executable_query table(const sql::table &table, const object::schema &schema) { executable_query table(const sql::table &table, const object::repository &schema) {
return this->table(table, object::attribute_definition_generator::generate<Type>(schema)); return this->table(table, object::attribute_definition_generator::generate<Type>(schema));
} }
}; };

View File

@ -14,7 +14,7 @@ public:
query_insert_intermediate(); query_insert_intermediate();
template<class Type> template<class Type>
query_into_intermediate into(const sql::table &table, const object::schema &schema) { query_into_intermediate into(const sql::table &table, const object::repository &schema) {
return into(table, sql::column_generator::generate<Type>(schema)); return into(table, sql::column_generator::generate<Type>(schema));
} }
query_into_intermediate into(const sql::table &table, std::initializer_list<sql::column> columns); query_into_intermediate into(const sql::table &table, std::initializer_list<sql::column> columns);

View File

@ -25,7 +25,7 @@ public:
[[nodiscard]] static query_select_intermediate select(const std::vector<std::string> &column_names); [[nodiscard]] static query_select_intermediate select(const std::vector<std::string> &column_names);
[[nodiscard]] static query_select_intermediate select(std::vector<sql::column> columns, std::initializer_list<sql::column> additional_columns); [[nodiscard]] static query_select_intermediate select(std::vector<sql::column> columns, std::initializer_list<sql::column> additional_columns);
template<class Type> template<class Type>
[[nodiscard]] static query_select_intermediate select(const object::schema &schema) { [[nodiscard]] static query_select_intermediate select(const object::repository &schema) {
return select(sql::column_generator::generate<Type>(schema)); return select(sql::column_generator::generate<Type>(schema));
} }
[[nodiscard]] static query_insert_intermediate insert(); [[nodiscard]] static query_insert_intermediate insert();

View File

@ -8,7 +8,7 @@
#include "matador/sql/column.hpp" #include "matador/sql/column.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
@ -20,14 +20,14 @@ class column_generator
{ {
private: private:
column_generator(std::vector<column> &column_infos, column_generator(std::vector<column> &column_infos,
const object::schema &ts, const object::repository &ts,
const std::string &table_name, const std::string &table_name,
bool force_lazy, bool force_lazy,
bool has_many_to_many = false); bool has_many_to_many = false);
public: public:
template < class Type > template < class Type >
static std::vector<column> generate(const object::schema &scm, const bool force_lazy = false) { static std::vector<column> generate(const object::repository &scm, const bool force_lazy = false) {
const auto info = scm.info<Type>(); const auto info = scm.info<Type>();
if (!info) { if (!info) {
return {}; return {};
@ -40,7 +40,7 @@ public:
} }
template < class Type > template < class Type >
static std::vector<column> generate_has_many_to_many(const object::schema &scm, const bool force_lazy = false) { static std::vector<column> generate_has_many_to_many(const object::repository &scm, const bool force_lazy = false) {
const auto info = scm.info<Type>(); const auto info = scm.info<Type>();
if (!info) { if (!info) {
return {}; return {};
@ -143,7 +143,7 @@ private:
std::stack<std::string> table_name_stack_; std::stack<std::string> table_name_stack_;
std::vector<column> &column_infos_; std::vector<column> &column_infos_;
std::unordered_set<std::string> seen_tables; std::unordered_set<std::string> seen_tables;
const object::schema &table_schema_; const object::repository &table_schema_;
int column_index{0}; int column_index{0};
bool force_lazy_{false}; bool force_lazy_{false};
bool has_many_to_many_{false}; bool has_many_to_many_{false};

View File

@ -18,7 +18,7 @@ add_library(matador-core STATIC
../../include/matador/object/basic_object_info.hpp ../../include/matador/object/basic_object_info.hpp
../../include/matador/object/error_code.hpp ../../include/matador/object/error_code.hpp
../../include/matador/object/foreign_node_completer.hpp ../../include/matador/object/foreign_node_completer.hpp
../../include/matador/object/internal/shadow_schema.hpp ../../include/matador/object/internal/shadow_repository.hpp
../../include/matador/object/many_to_many_relation.hpp ../../include/matador/object/many_to_many_relation.hpp
../../include/matador/object/object_definition.hpp ../../include/matador/object/object_definition.hpp
../../include/matador/object/object_info.hpp ../../include/matador/object/object_info.hpp
@ -27,9 +27,9 @@ add_library(matador-core STATIC
../../include/matador/object/primary_key_resolver.hpp ../../include/matador/object/primary_key_resolver.hpp
../../include/matador/object/relation_completer.hpp ../../include/matador/object/relation_completer.hpp
../../include/matador/object/relation_endpoint.hpp ../../include/matador/object/relation_endpoint.hpp
../../include/matador/object/schema.hpp ../../include/matador/object/repository.hpp
../../include/matador/object/schema_node.hpp ../../include/matador/object/repository_node.hpp
../../include/matador/object/schema_node_iterator.hpp ../../include/matador/object/repository_node_iterator.hpp
../../include/matador/sql/statement_cache.hpp ../../include/matador/sql/statement_cache.hpp
../../include/matador/utils/access.hpp ../../include/matador/utils/access.hpp
../../include/matador/utils/attribute_reader.hpp ../../include/matador/utils/attribute_reader.hpp
@ -80,12 +80,12 @@ add_library(matador-core STATIC
object/basic_object_info.cpp object/basic_object_info.cpp
object/error_code.cpp object/error_code.cpp
object/foreign_node_completer.cpp object/foreign_node_completer.cpp
object/internal/shadow_schema.cpp object/internal/shadow_repository.cpp
object/object_definition.cpp object/object_definition.cpp
object/relation_endpoint.cpp object/relation_endpoint.cpp
object/schema.cpp object/repository.cpp
object/schema_node.cpp object/repository_node.cpp
object/schema_node_iterator.cpp object/repository_node_iterator.cpp
utils/default_type_traits.cpp utils/default_type_traits.cpp
utils/error.cpp utils/error.cpp
utils/errors.cpp utils/errors.cpp

View File

@ -1,9 +1,9 @@
#include "matador/object/attribute_definition_generator.hpp" #include "matador/object/attribute_definition_generator.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
namespace matador::object { namespace matador::object {
attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, const schema &repo) attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, const repository &repo)
: columns_(columns) : columns_(columns)
, repo_(repo) , repo_(repo)
{} {}
@ -18,7 +18,7 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> attribute_def
} }
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, std::shared_ptr<attribute_definition> ref_column) const { void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, std::shared_ptr<attribute_definition> ref_column) const {
const_cast<schema&>(repo_).missing_references_.insert({ti, ref_column}); const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
} }
} }

View File

@ -1,11 +1,11 @@
#include "matador/object/basic_object_info.hpp" #include "matador/object/basic_object_info.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
#include <algorithm> #include <algorithm>
namespace matador::object { namespace matador::object {
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node, basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &pk_column, const std::shared_ptr<attribute_definition> &pk_column,
object_definition &&definition) object_definition &&definition)
@ -15,7 +15,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
, pk_column_(pk_column) { , pk_column_(pk_column) {
} }
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node, basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &pk_column) const std::shared_ptr<attribute_definition> &pk_column)
: node_(std::move(node)) : node_(std::move(node))
@ -23,7 +23,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
, pk_column_(pk_column) { , pk_column_(pk_column) {
} }
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node, basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
object_definition &&definition) object_definition &&definition)
: node_(std::move(node)) : node_(std::move(node))
, definition_(std::move(definition)) {} , definition_(std::move(definition)) {}

View File

@ -1,11 +1,11 @@
#include "matador/object/foreign_node_completer.hpp" #include "matador/object/foreign_node_completer.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/logger/logger.hpp" #include "matador/logger/logger.hpp"
namespace matador::object { namespace matador::object {
foreign_node_completer::foreign_node_completer(internal::shadow_schema &shadow) foreign_node_completer::foreign_node_completer(internal::shadow_repository &shadow)
: schema_(shadow) : repo_(shadow)
, log_(logger::create_logger("node_completer")) {} , log_(logger::create_logger("node_completer")) {}
} }

View File

@ -0,0 +1,33 @@
#include "matador/object/internal/shadow_repository.hpp"
#include "matador/object/repository.hpp"
#include "matador/object/repository_node.hpp"
namespace matador::object::internal {
shadow_repository::shadow_repository( object::repository& s )
: schema_(s) {}
repository& shadow_repository::repo() const {
return schema_;
}
bool shadow_repository::contains( const std::type_index& ti ) const {
return schema_.contains(ti);
}
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::find_node( const std::type_index& type_index ) const {
return schema_.find_node(type_index);
}
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::find_node( const std::string& name ) const {
return schema_.find_node(name);
}
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::attach_node( const std::shared_ptr<repository_node>& node ) const {
return schema_.attach_node(node, "");
}
utils::result<void, utils::error> shadow_repository::detach_node( const std::shared_ptr<repository_node>& node ) const {
return schema_.detach(node);
}
}

View File

@ -1,33 +0,0 @@
#include "matador/object/internal/shadow_schema.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/schema_node.hpp"
namespace matador::object::internal {
shadow_schema::shadow_schema( object::schema& s )
: schema_(s) {}
schema& shadow_schema::schema() const {
return schema_;
}
bool shadow_schema::schema_contains( const std::type_index& ti ) const {
return schema_.contains(ti);
}
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( const std::type_index& type_index ) const {
return schema_.find_node(type_index);
}
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( const std::string& name ) const {
return schema_.find_node(name);
}
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::attach_node( const std::shared_ptr<schema_node>& node ) const {
return schema_.attach_node(node, "");
}
utils::result<void, utils::error> shadow_schema::detach_node( const std::shared_ptr<schema_node>& node ) const {
return schema_.detach(node);
}
}

View File

@ -1,9 +1,9 @@
#include "matador/object/relation_endpoint.hpp" #include "matador/object/relation_endpoint.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
namespace matador::object { namespace matador::object {
relation_endpoint::relation_endpoint(std::string field_name, const relation_type type, const std::shared_ptr<schema_node> &node) relation_endpoint::relation_endpoint(std::string field_name, const relation_type type, const std::shared_ptr<repository_node> &node)
: field_name_(std::move(field_name)) : field_name_(std::move(field_name))
, type_(type) , type_(type)
, node_(node) { , node_(node) {
@ -21,11 +21,11 @@ std::string relation_endpoint::type_name() const {
return relation_type_enum.to_string(type_); return relation_type_enum.to_string(type_);
} }
const schema_node &relation_endpoint::node() const { const repository_node &relation_endpoint::node() const {
return *node_; return *node_;
} }
std::shared_ptr<schema_node> relation_endpoint::node_ptr() const { std::shared_ptr<repository_node> relation_endpoint::node_ptr() const {
return node_; return node_;
} }

View File

@ -1,202 +1,202 @@
#include <utility> #include <utility>
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
namespace matador::object { namespace matador::object {
utils::error make_error(const error_code ec, const std::string &msg) { utils::error make_error(const error_code ec, const std::string &msg) {
return utils::error(ec, msg); return utils::error(ec, msg);
} }
schema::schema(std::string name) repository::repository(std::string name)
: name_(std::move(name)) : name_(std::move(name))
, root_(schema_node::make_null_node(*this)) , root_(repository_node::make_null_node(*this))
, log_(logger::create_logger("schema")) { , log_(logger::create_logger("schema")) {
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this)); root_->first_child_ = std::shared_ptr<repository_node>(new repository_node(*this));
root_->last_child_ = std::shared_ptr<schema_node>(new schema_node(*this)); root_->last_child_ = std::shared_ptr<repository_node>(new repository_node(*this));
root_->first_child_->next_sibling_ = root_->last_child_; root_->first_child_->next_sibling_ = root_->last_child_;
root_->last_child_->previous_sibling_ = root_->first_child_; root_->last_child_->previous_sibling_ = root_->first_child_;
} }
utils::result<void, utils::error> schema::detach(const node_ptr &node) { utils::result<void, utils::error> repository::detach(const node_ptr &node) {
log_.debug("detach node '%s' (type: %s)", node->name().c_str(), node->type_index().name()); log_.debug("detach node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
remove_node(node); remove_node(node);
return utils::ok<void>(); return utils::ok<void>();
} }
schema::const_iterator schema::begin() const { repository::const_iterator repository::begin() const {
return const_iterator(root_->first_child_->next_sibling_); return const_iterator(root_->first_child_->next_sibling_);
} }
schema::const_iterator schema::end() const { repository::const_iterator repository::end() const {
return const_iterator(root_->last_child_); return const_iterator(root_->last_child_);
} }
bool schema::empty() const { bool repository::empty() const {
return root_->first_child_ == root_->last_child_->previous_sibling_; return root_->first_child_ == root_->last_child_->previous_sibling_;
} }
size_t schema::size() const { size_t repository::size() const {
return static_cast<size_t>(std::distance(begin(), end())); return static_cast<size_t>(std::distance(begin(), end()));
} }
std::string schema::name() const { std::string repository::name() const {
return name_; return name_;
} }
bool schema::contains( const std::string& name ) const { bool repository::contains( const std::string& name ) const {
return nodes_by_name_.count(name) > 0; return nodes_by_name_.count(name) > 0;
} }
bool schema::contains( const std::type_index& index ) const { bool repository::contains( const std::type_index& index ) const {
return nodes_by_type_.count(index) > 0; return nodes_by_type_.count(index) > 0;
} }
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference_column(const std::type_index &type_index) const { utils::result<std::shared_ptr<attribute_definition>, utils::error> repository::reference_column(const std::type_index &type_index) const {
const auto result = find_node(type_index); const auto result = find_node(type_index);
if (result) { if (result) {
return utils::ok((*result)->info().reference_column()); return utils::ok((*result)->info().reference_column());
} }
return utils::failure(result.err()); return utils::failure(result.err());
} }
void schema::dump(std::ostream &os) const { void repository::dump(std::ostream &os) const {
for (const auto &node : *this) { for (const auto &node : *this) {
dump(os, node); dump(os, node);
} }
os << "\n"; os << "\n";
} }
void schema::dump( std::ostream& os, const node_ptr& node ) { void repository::dump( std::ostream& os, const node_ptr& node ) {
os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n"; os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n";
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) { for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")"; os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")";
if (it->second->foreign_endpoint()) { if (it->second->foreign_endpoint()) {
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n"; os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
} else { } else {
os << " -> " << it->second->node().name() << " (type: " << it->second->node().type_index().name() << ")\n"; os << " -> " << it->second->node().name() << " (type: " << it->second->node().type_index().name() << ")\n";
} }
} }
} }
utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node, utils::result<repository::node_ptr, utils::error> repository::attach_node(const std::shared_ptr<repository_node> &node,
const std::string &parent) { const std::string &parent) {
if (has_node(node)) { if (has_node(node)) {
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists.")); return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
} }
log_.info("attach: insert node '%s' (type: %s)", node->name().c_str(), node->type_index().name()); log_.info("attach: insert node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
// set node to root node // set node to root node
auto parent_node = root_; auto parent_node = root_;
if (!parent.empty()) { if (!parent.empty()) {
auto result = find_node(parent); auto result = find_node(parent);
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) { if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
return result; return result;
} }
parent_node = *result; parent_node = *result;
} }
insert_node(parent_node, node); insert_node(parent_node, node);
// Todo: check return value // Todo: check return value
nodes_by_name_.insert({node->name(), node}); nodes_by_name_.insert({node->name(), node});
nodes_by_type_.insert({node->type_index(), node}); nodes_by_type_.insert({node->type_index(), node});
return utils::ok(node); return utils::ok(node);
} }
// utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node, // utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
// const std::type_index &type_index) { // const std::type_index &type_index) {
// if (has_node(node)) { // if (has_node(node)) {
// return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists.")); // return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
// } // }
// auto result = find_node(type_index); // auto result = find_node(type_index);
// if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) { // if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
// return result; // return result;
// } // }
// //
// insert_node(*result, node); // insert_node(*result, node);
// //
// // Todo: check return value // // Todo: check return value
// nodes_by_name_.insert({node->name(), node})/*.first*/; // nodes_by_name_.insert({node->name(), node})/*.first*/;
// nodes_by_type_.insert({node->type_index(), node}); // nodes_by_type_.insert({node->type_index(), node});
// //
// return utils::ok(node); // return utils::ok(node);
// } // }
utils::result<schema::node_ptr, utils::error> schema::find_node(const std::string &name) const { utils::result<repository::node_ptr, utils::error> repository::find_node(const std::string &name) const {
// first search in the prototype map // first search in the prototype map
const auto i = nodes_by_name_.find(name); const auto i = nodes_by_name_.find(name);
if (i == nodes_by_name_.end()) { if (i == nodes_by_name_.end()) {
return utils::failure(make_error(error_code::NodeNotFound, "Couldn't find node by name '" + name + "'")); return utils::failure(make_error(error_code::NodeNotFound, "Couldn't find node by name '" + name + "'"));
} }
return utils::ok(i->second); return utils::ok(i->second);
} }
utils::result<schema::node_ptr, utils::error> schema::find_node(const std::type_index &type_index) const { utils::result<repository::node_ptr, utils::error> repository::find_node(const std::type_index &type_index) const {
const auto i = nodes_by_type_.find(type_index); const auto i = nodes_by_type_.find(type_index);
if (i == nodes_by_type_.end()) { if (i == nodes_by_type_.end()) {
return utils::failure(make_error(error_code::NodeNotFound, return utils::failure(make_error(error_code::NodeNotFound,
"Couldn't find node by type '" + std::string(type_index.name()) + "'")); "Couldn't find node by type '" + std::string(type_index.name()) + "'"));
} }
return utils::ok(i->second); return utils::ok(i->second);
} }
void schema::insert_node(const node_ptr &parent, const node_ptr &child) { void repository::insert_node(const node_ptr &parent, const node_ptr &child) {
child->parent_ = parent; child->parent_ = parent;
child->previous_sibling_ = parent->last_child_->previous_sibling_; child->previous_sibling_ = parent->last_child_->previous_sibling_;
child->next_sibling_ = parent->last_child_; child->next_sibling_ = parent->last_child_;
/* /*
* +-----------------------------<- (first) parent (last) -> ----------------------------+ * +-----------------------------<- (first) parent (last) -> ----------------------------+
* | | * | |
* first (next) -> <- (prev) child_1 (next) -> <- (prev) new_child (next) -> <- (prev) last * first (next) -> <- (prev) child_1 (next) -> <- (prev) new_child (next) -> <- (prev) last
* ^^^^^^^ inserted ^^^^^^ * ^^^^^^^ inserted ^^^^^^
*/ */
parent->last_child_->previous_sibling_->next_sibling_ = child; parent->last_child_->previous_sibling_->next_sibling_ = child;
parent->last_child_->previous_sibling_ = child; parent->last_child_->previous_sibling_ = child;
// set depth // set depth
// child->depth = depth + 1; // child->depth = depth + 1;
} }
void schema::remove_node(const node_ptr &node) { void repository::remove_node(const node_ptr &node) {
auto next = node->next(); auto next = node->next();
std::stack<node_ptr> nodes_to_remove; std::stack<node_ptr> nodes_to_remove;
nodes_to_remove.push(node); nodes_to_remove.push(node);
while (!nodes_to_remove.empty()) { while (!nodes_to_remove.empty()) {
const auto current = nodes_to_remove.top(); const auto current = nodes_to_remove.top();
if (current->has_children()) { if (current->has_children()) {
// Push all children to the stack (from right to left to maintain order) // Push all children to the stack (from right to left to maintain order)
auto child = current->last_child_->previous_sibling_; auto child = current->last_child_->previous_sibling_;
while (child != current->first_child_) { while (child != current->first_child_) {
nodes_to_remove.push(child); nodes_to_remove.push(child);
child = child->previous_sibling_; child = child->previous_sibling_;
} }
continue; continue;
} }
// No children left, safe to remove this node // No children left, safe to remove this node
nodes_to_remove.pop(); nodes_to_remove.pop();
current->unlink(); current->unlink();
nodes_by_name_.erase(current->name()); nodes_by_name_.erase(current->name());
nodes_by_type_.erase(current->type_index()); nodes_by_type_.erase(current->type_index());
} }
} }
bool schema::has_node(const std::string &name) const { bool repository::has_node(const std::string &name) const {
return nodes_by_name_.count(name) > 0; return nodes_by_name_.count(name) > 0;
} }
bool schema::has_node(const std::type_index &index) const { bool repository::has_node(const std::type_index &index) const {
return nodes_by_type_.count(index) > 0; return nodes_by_type_.count(index) > 0;
} }
bool schema::has_node(const node_ptr& node) const { bool repository::has_node(const node_ptr& node) const {
return nodes_by_name_.count(node->name()) > 0 || nodes_by_type_.count(node->type_index()) > 0; return nodes_by_name_.count(node->name()) > 0 || nodes_by_type_.count(node->type_index()) > 0;
} }
} // namespace matador::object } // namespace matador::object

View File

@ -1,62 +1,62 @@
#include <utility> #include <utility>
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/object/schema_node.hpp" #include "matador/object/repository_node.hpp"
namespace matador::object { namespace matador::object {
schema_node::schema_node(object::schema &tree) repository_node::repository_node(object::repository &tree)
: schema_(tree) : repo_(tree)
, type_index_(typeid(detail::null_type)){ , type_index_(typeid(detail::null_type)){
} }
schema_node::schema_node(object::schema &tree, const std::type_index& ti) repository_node::repository_node(object::repository &tree, const std::type_index& ti)
: schema_(tree) : repo_(tree)
, type_index_(ti) { , type_index_(ti) {
} }
schema_node::schema_node(object::schema &tree, std::string name, const std::type_index& ti) repository_node::repository_node(object::repository &tree, std::string name, const std::type_index& ti)
: schema_(tree) : repo_(tree)
, type_index_(ti) , type_index_(ti)
, first_child_(std::shared_ptr<schema_node>(new schema_node(tree))) , first_child_(std::shared_ptr<repository_node>(new repository_node(tree)))
, last_child_(std::shared_ptr<schema_node>(new schema_node(tree))) , last_child_(std::shared_ptr<repository_node>(new repository_node(tree)))
, name_(std::move(name)) { , name_(std::move(name)) {
first_child_->next_sibling_ = last_child_; first_child_->next_sibling_ = last_child_;
last_child_->previous_sibling_ = first_child_; last_child_->previous_sibling_ = first_child_;
} }
std::shared_ptr<schema_node> schema_node::make_null_node(object::schema &tree) { std::shared_ptr<repository_node> repository_node::make_null_node(object::repository &tree) {
auto node = std::shared_ptr<schema_node>(new schema_node(tree)); auto node = std::shared_ptr<repository_node>(new repository_node(tree));
node->info_ = std::make_unique<null_info>(node, std::shared_ptr<attribute_definition>{}); node->info_ = std::make_unique<null_info>(node, std::shared_ptr<attribute_definition>{});
return node; return node;
} }
std::string schema_node::name() const { std::string repository_node::name() const {
return name_; return name_;
} }
std::type_index schema_node::type_index() const { std::type_index repository_node::type_index() const {
return type_index_; return type_index_;
} }
const basic_object_info &schema_node::info() const { const basic_object_info &repository_node::info() const {
return *info_; return *info_;
} }
void schema_node::update_name(const std::string& name) { void repository_node::update_name(const std::string& name) {
name_ = name; name_ = name;
info_->reference_column()->table_name(name); info_->reference_column()->table_name(name);
} }
const object::schema& schema_node::schema() const { const object::repository& repository_node::schema() const {
return schema_; return repo_;
} }
bool schema_node::has_children() const { bool repository_node::has_children() const {
return first_child_->next_sibling_ != last_child_; return first_child_->next_sibling_ != last_child_;
} }
schema_node::node_ptr schema_node::next() const { repository_node::node_ptr repository_node::next() const {
// if we have a child, child is the next iterator to return // if we have a child, child is the next iterator to return
// (if we don't iterate over the siblings) // (if we don't iterate over the siblings)
if (first_child_ && first_child_->next_sibling_ != last_child_) { if (first_child_ && first_child_->next_sibling_ != last_child_) {
@ -72,7 +72,7 @@ schema_node::node_ptr schema_node::next() const {
return node->parent_ ? node->next_sibling_ : node->last_child_; return node->parent_ ? node->next_sibling_ : node->last_child_;
} }
schema_node::node_ptr schema_node::prev() const { repository_node::node_ptr repository_node::prev() const {
// if the node has a previous sibling, we set it // if the node has a previous sibling, we set it
// as our next iterator. then we check if there // as our next iterator. then we check if there
// are last children. if so, we set the last-last // are last children. if so, we set the last-last
@ -89,20 +89,20 @@ schema_node::node_ptr schema_node::prev() const {
return parent_->parent_ ? parent_ : parent_->first_child_->next_sibling_; return parent_->parent_ ? parent_ : parent_->first_child_->next_sibling_;
} }
void schema_node::unlink() { void repository_node::unlink() {
previous_sibling_->next_sibling_ = next_sibling_; previous_sibling_->next_sibling_ = next_sibling_;
next_sibling_->previous_sibling_ = previous_sibling_; next_sibling_->previous_sibling_ = previous_sibling_;
next_sibling_.reset(); next_sibling_.reset();
previous_sibling_.reset(); previous_sibling_.reset();
} }
utils::result<schema_node::node_ptr, utils::error> schema_node::make_and_attach_node(object::schema& tree, const std::string& name, const std::type_index& ti) { utils::result<repository_node::node_ptr, utils::error> repository_node::make_and_attach_node(object::repository& tree, const std::string& name, const std::type_index& ti) {
const auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, ti)); const auto node = std::shared_ptr<repository_node>(new repository_node(tree, name, ti));
return tree.attach_node(node, ""); return tree.attach_node(node, "");
} }
std::shared_ptr<attribute_definition> schema_node::determine_reference_column(const std::type_index& ti, const std::string& name, const primary_key_info& pk_info, object::schema& tree) { std::shared_ptr<attribute_definition> repository_node::determine_reference_column(const std::type_index& ti, const std::string& name, const primary_key_info& pk_info, object::repository& tree) {
const auto it = tree.missing_references_.find(ti); const auto it = tree.missing_references_.find(ti);
if (it == tree.missing_references_.end()) { if (it == tree.missing_references_.end()) {
return std::make_shared<attribute_definition>(pk_info.pk_column_name, name, pk_info.type, utils::constraints::FOREIGN_KEY); return std::make_shared<attribute_definition>(pk_info.pk_column_name, name, pk_info.type, utils::constraints::FOREIGN_KEY);

View File

@ -0,0 +1,78 @@
#include <utility>
#include "matador/object/repository_node_iterator.hpp"
namespace matador::object {
const_repository_node_iterator::const_repository_node_iterator(const value_type& node)
: node_(node)
{}
bool const_repository_node_iterator::operator==(const const_repository_node_iterator &i) const
{
return (node_ == i.node_);
}
bool const_repository_node_iterator::operator!=(const const_repository_node_iterator &i) const
{
return !operator==(i);
}
const_repository_node_iterator& const_repository_node_iterator::operator++()
{
increment();
return *this;
}
const_repository_node_iterator const_repository_node_iterator::operator++( int ) {
const value_type tmp = node_;
increment();
return const_repository_node_iterator(tmp);
}
const_repository_node_iterator& const_repository_node_iterator::operator--()
{
decrement();
return *this;
}
const_repository_node_iterator const_repository_node_iterator::operator--(int)
{
const value_type tmp = node_;
decrement();
return const_repository_node_iterator(tmp);
}
const_repository_node_iterator::pointer const_repository_node_iterator::operator->() const
{
return node_.get();
}
const_repository_node_iterator::reference const_repository_node_iterator::operator*() const
{
return node_;
}
const_repository_node_iterator::pointer const_repository_node_iterator::get() const
{
return node_.get();
}
void const_repository_node_iterator::increment()
{
if (!node_) {
return;
}
node_ = node_->next();
}
void const_repository_node_iterator::decrement()
{
if (!node_) {
return;
}
node_ = node_->prev();
}
}

View File

@ -1,78 +0,0 @@
#include <utility>
#include "matador/object/schema_node_iterator.hpp"
namespace matador::object {
const_schema_node_iterator::const_schema_node_iterator(const value_type& node)
: node_(node)
{}
bool const_schema_node_iterator::operator==(const const_schema_node_iterator &i) const
{
return (node_ == i.node_);
}
bool const_schema_node_iterator::operator!=(const const_schema_node_iterator &i) const
{
return !operator==(i);
}
const_schema_node_iterator& const_schema_node_iterator::operator++()
{
increment();
return *this;
}
const_schema_node_iterator const_schema_node_iterator::operator++( int ) {
const value_type tmp = node_;
increment();
return const_schema_node_iterator(tmp);
}
const_schema_node_iterator& const_schema_node_iterator::operator--()
{
decrement();
return *this;
}
const_schema_node_iterator const_schema_node_iterator::operator--(int)
{
const value_type tmp = node_;
decrement();
return const_schema_node_iterator(tmp);
}
const_schema_node_iterator::pointer const_schema_node_iterator::operator->() const
{
return node_.get();
}
const_schema_node_iterator::reference const_schema_node_iterator::operator*() const
{
return node_;
}
const_schema_node_iterator::pointer const_schema_node_iterator::get() const
{
return node_.get();
}
void const_schema_node_iterator::increment()
{
if (!node_) {
return;
}
node_ = node_->next();
}
void const_schema_node_iterator::decrement()
{
if (!node_) {
return;
}
node_ = node_->prev();
}
}

View File

@ -15,13 +15,13 @@ utils::error make_error(const error_code ec, const std::string &msg) {
session::session(session_context&& ctx) session::session(session_context&& ctx)
: cache_(ctx.bus, ctx.pool, ctx.cache_size) : cache_(ctx.bus, ctx.pool, ctx.cache_size)
, dialect_(sql::backend_provider::instance().connection_dialect(ctx.pool.info().type)) , dialect_(sql::backend_provider::instance().connection_dialect(ctx.pool.info().type))
, schema_(std::make_unique<object::schema>(dialect_.default_schema_name())) { , schema_(std::make_unique<object::repository>(dialect_.default_schema_name())) {
} }
utils::result<void, utils::error> session::create_schema() const { utils::result<void, utils::error> session::create_schema() const {
// Step 1: Build dependency graph // Step 1: Build dependency graph
std::unordered_map<std::string, std::vector<std::string> > dependency_graph; std::unordered_map<std::string, std::vector<std::string> > dependency_graph;
std::unordered_map<std::string, std::pair<int,object::schema::node_ptr>> in_degree; std::unordered_map<std::string, std::pair<int,object::repository::node_ptr>> in_degree;
for (const auto &node: *schema_) { for (const auto &node: *schema_) {
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) { for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {

View File

@ -5,7 +5,7 @@
namespace matador::sql { namespace matador::sql {
column_generator::column_generator(std::vector<column> &column_infos, column_generator::column_generator(std::vector<column> &column_infos,
const object::schema &scm, const object::repository &scm,
const std::string &table_name, const std::string &table_name,
const bool force_lazy, const bool force_lazy,
const bool has_many_to_many) const bool has_many_to_many)

View File

@ -2,7 +2,7 @@
#include "catch2/matchers/catch_matchers_string.hpp" #include "catch2/matchers/catch_matchers_string.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute_definition.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
#include "matador/sql/column_generator.hpp" #include "matador/sql/column_generator.hpp"
@ -25,9 +25,9 @@ using namespace matador::object;
using namespace matador::query; using namespace matador::query;
TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][datatypes]" ) { TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][datatypes]" ) {
REQUIRE(schema.attach<types>("types")); REQUIRE(repo.attach<types>("types"));
auto res = query::create() auto res = query::create()
.table<types>("types", schema) .table<types>("types", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -74,13 +74,13 @@ TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][da
}; };
res = query::insert() res = query::insert()
.into("types", column_generator::generate<types>(schema, true)) .into("types", column_generator::generate<types>(repo, true))
.values(t) .values(t)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto result = query::select<types>(schema) auto result = query::select<types>(repo)
.from("types") .from("types")
.fetch_one<types>(db); .fetch_one<types>(db);
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
@ -278,9 +278,9 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]") { TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]") {
using namespace matador::sql; using namespace matador::sql;
REQUIRE(schema.attach<types>("types")); REQUIRE(repo.attach<types>("types"));
const auto res = query::create() const auto res = query::create()
.table<types>("types", schema) .table<types>("types", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -351,9 +351,9 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
using namespace matador::test::temporary; using namespace matador::test::temporary;
using namespace matador::sql; using namespace matador::sql;
REQUIRE(schema.attach<pk>("pk")); REQUIRE(repo.attach<pk>("pk"));
auto res = query::create() auto res = query::create()
.table<pk>("pk", schema) .table<pk>("pk", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -362,13 +362,13 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
pk pk1{ 7, "george" }; pk pk1{ 7, "george" };
res = query::insert() res = query::insert()
.into("pk", column_generator::generate<pk>(schema)) .into("pk", column_generator::generate<pk>(repo))
.values(pk1) .values(pk1)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto row = query::select<pk>(schema) auto row = query::select<pk>(repo)
.from("pk") .from("pk")
.fetch_one<pk>(db); .fetch_one<pk>(db);
REQUIRE(row.is_ok()); REQUIRE(row.is_ok());
@ -380,9 +380,9 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
using namespace matador::test::temporary; using namespace matador::test::temporary;
using namespace matador::sql; using namespace matador::sql;
REQUIRE(schema.attach<pk>("pk")); REQUIRE(repo.attach<pk>("pk"));
auto res = query::create() auto res = query::create()
.table<pk>("pk", schema) .table<pk>("pk", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -391,7 +391,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
pk pk1{ 7, "george" }; pk pk1{ 7, "george" };
auto stmt = query::insert() auto stmt = query::insert()
.into("pk", column_generator::generate<pk>(schema)) .into("pk", column_generator::generate<pk>(repo))
.values<pk>() .values<pk>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -401,7 +401,7 @@ REQUIRE(stmt);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
stmt = query::select<pk>(schema) stmt = query::select<pk>(repo)
.from("pk") .from("pk")
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);

View File

@ -10,7 +10,7 @@ namespace matador::test {
QueryFixture::QueryFixture() QueryFixture::QueryFixture()
: db(connection::dns) : db(connection::dns)
, schema(db.dialect().default_schema_name()) , repo(db.dialect().default_schema_name())
{ {
REQUIRE(db.open()); REQUIRE(db.open());
} }

View File

@ -1,7 +1,7 @@
#ifndef MATADOR_QUERY_FIXTURE_HPP #ifndef MATADOR_QUERY_FIXTURE_HPP
#define MATADOR_QUERY_FIXTURE_HPP #define MATADOR_QUERY_FIXTURE_HPP
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
@ -22,7 +22,7 @@ public:
protected: protected:
sql::connection db; sql::connection db;
std::stack <std::string> tables_to_drop; std::stack <std::string> tables_to_drop;
object::schema schema; object::repository repo;
private: private:
void drop_table_if_exists(const std::string &table_name) const; void drop_table_if_exists(const std::string &table_name) const;

View File

@ -19,9 +19,9 @@ using namespace matador::query;
using namespace matador::test; using namespace matador::test;
TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") { TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") {
REQUIRE(schema.attach<matador::test::person>("person")); REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create() auto stmt = query::create()
.table<matador::test::person>("person", schema) .table<matador::test::person>("person", repo)
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -43,9 +43,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][crea
TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][insert]") { TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][insert]") {
using namespace matador::test; using namespace matador::test;
REQUIRE(schema.attach<person>("person")); REQUIRE(repo.attach<person>("person"));
auto stmt = query::create() auto stmt = query::create()
.table<person>("person", schema) .table<person>("person", repo)
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -59,7 +59,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
person george{1, "george", 45, {1,2,3,4}}; person george{1, "george", 45, {1,2,3,4}};
stmt = query::insert() stmt = query::insert()
.into<person>("person", schema) .into<person>("person", repo)
.values<person>() .values<person>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -69,7 +69,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto row = query::select<person>(schema) auto row = query::select<person>(repo)
.from("person") .from("person")
.fetch_one<person>(db); .fetch_one<person>(db);
REQUIRE(row.is_ok()); REQUIRE(row.is_ok());
@ -85,9 +85,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
using namespace matador::test; using namespace matador::test;
using namespace matador::utils; using namespace matador::utils;
REQUIRE(schema.attach<matador::test::person>("person")); REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create() auto stmt = query::create()
.table<matador::test::person>("person", schema) .table<matador::test::person>("person", repo)
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -101,7 +101,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
person george{1, "george", 45, {1,2,3,4}}; person george{1, "george", 45, {1,2,3,4}};
stmt = query::insert() stmt = query::insert()
.into<person>("person", schema) .into<person>("person", repo)
.values<person>() .values<person>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -111,7 +111,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto row = query::select<person>(schema) auto row = query::select<person>(repo)
.from("person") .from("person")
.fetch_one<person>(db); .fetch_one<person>(db);
REQUIRE(row.is_ok()); REQUIRE(row.is_ok());
@ -136,7 +136,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
row = query::select<person>(schema) row = query::select<person>(repo)
.from("person") .from("person")
.fetch_one<person>(db); .fetch_one<person>(db);
REQUIRE(row.is_ok()); REQUIRE(row.is_ok());
@ -151,9 +151,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][delete]") { TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][delete]") {
using namespace matador::test; using namespace matador::test;
REQUIRE(schema.attach<matador::test::person>("person")); REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create() auto stmt = query::create()
.table<matador::test::person>("person", schema) .table<matador::test::person>("person", repo)
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -165,7 +165,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
check_table_exists("person"); check_table_exists("person");
stmt = query::insert() stmt = query::insert()
.into<person>("person", schema) .into<person>("person", repo)
.values<person>() .values<person>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -185,7 +185,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
stmt->reset(); stmt->reset();
} }
auto select_stmt = query::select<person>(schema) auto select_stmt = query::select<person>(repo)
.from("person") .from("person")
.where("name"_col == matador::utils::_) .where("name"_col == matador::utils::_)
.prepare(db); .prepare(db);
@ -238,9 +238,9 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][statement][reuse]") { TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][statement][reuse]") {
using namespace matador::test; using namespace matador::test;
REQUIRE(schema.attach<matador::test::person>("person")); REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create() auto stmt = query::create()
.table<matador::test::person>("person", schema) .table<matador::test::person>("person", repo)
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -252,7 +252,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
check_table_exists("person"); check_table_exists("person");
stmt = query::insert() stmt = query::insert()
.into<person>("person", schema) .into<person>("person", repo)
.values<person>() .values<person>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -272,7 +272,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
stmt->reset(); stmt->reset();
} }
stmt = query::select<person>(schema) stmt = query::select<person>(repo)
.from("person") .from("person")
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);

View File

@ -20,12 +20,12 @@ using namespace matador::sql;
using namespace matador::test; using namespace matador::test;
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query][foreign][relation]") { TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query][foreign][relation]") {
auto result = schema.attach<airplane>("airplane") auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} ); .and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
auto res = query::create() auto res = query::create()
.table<airplane>("airplane", schema) .table<airplane>("airplane", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -34,7 +34,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
tables_to_drop.emplace("airplane"); tables_to_drop.emplace("airplane");
res = query::create() res = query::create()
.table<flight>("flight", schema) .table<flight>("flight", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -44,9 +44,9 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
} }
TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[query][where]") { TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[query][where]") {
REQUIRE(schema.attach<person>("person")); REQUIRE(repo.attach<person>("person"));
auto res = query::create() auto res = query::create()
.table<person>("person", schema) .table<person>("person", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -58,14 +58,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
george.image.emplace_back(37); george.image.emplace_back(37);
res = query::insert() res = query::insert()
.into("person", column_generator::generate<person>(schema, true)) .into("person", column_generator::generate<person>(repo, true))
.values(george) .values(george)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
// fetch person as record // fetch person as record
auto result_record = query::select(column_generator::generate<person>(schema, true)) auto result_record = query::select(column_generator::generate<person>(repo, true))
.from("person") .from("person")
.where("id"_col == 7) .where("id"_col == 7)
.fetch_all(db); .fetch_all(db);
@ -85,7 +85,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
} }
// fetch person as person // fetch person as person
auto result_person = query::select(column_generator::generate<person>(schema, true)) auto result_person = query::select(column_generator::generate<person>(repo, true))
.from("person") .from("person")
.where("id"_col == 7) .where("id"_col == 7)
.fetch_all<person>(db); .fetch_all<person>(db);
@ -141,12 +141,12 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
} }
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][foreign]") { TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][foreign]") {
auto result = schema.attach<airplane>("airplane") auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} ); .and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
auto res = query::create() auto res = query::create()
.table<airplane>("airplane", schema) .table<airplane>("airplane", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -155,7 +155,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
tables_to_drop.emplace("airplane"); tables_to_drop.emplace("airplane");
res = query::create() res = query::create()
.table<flight>("flight", schema) .table<flight>("flight", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -171,7 +171,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
for (const auto &plane: planes) { for (const auto &plane: planes) {
res = query::insert() res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true)) .into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane) .values(*plane)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
@ -187,13 +187,13 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
flight f4711{4, planes.at(1), "hans"}; flight f4711{4, planes.at(1), "hans"};
res = query::insert() res = query::insert()
.into("flight", column_generator::generate<flight>(schema, true)) .into("flight", column_generator::generate<flight>(repo, true))
.values(f4711) .values(f4711)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto f = query::select(column_generator::generate<flight>(schema, true)) auto f = query::select(column_generator::generate<flight>(repo, true))
.from("flight") .from("flight")
.fetch_one(db); .fetch_one(db);
REQUIRE(f.is_ok()); REQUIRE(f.is_ok());
@ -204,12 +204,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
} }
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left", "[query][foreign][join_left]") { TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left", "[query][foreign][join_left]") {
auto result = schema.attach<airplane>("airplane") auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} ); .and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
auto res = query::create() auto res = query::create()
.table<airplane>("airplane", schema) .table<airplane>("airplane", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -218,7 +218,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
tables_to_drop.emplace("airplane"); tables_to_drop.emplace("airplane");
res = query::create() res = query::create()
.table<flight>("flight", schema) .table<flight>("flight", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -234,7 +234,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
for (const auto &plane: planes) { for (const auto &plane: planes) {
res = query::insert() res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true)) .into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane) .values(*plane)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
@ -262,7 +262,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
REQUIRE(*res == 1); REQUIRE(*res == 1);
} }
auto f = query::select(column_generator::generate<flight>(schema, true)) auto f = query::select(column_generator::generate<flight>(repo, true))
.from("flight") .from("flight")
.fetch_one(db); .fetch_one(db);
REQUIRE(f.is_ok()); REQUIRE(f.is_ok());
@ -294,12 +294,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
} }
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single entity", "[query][join_left][find]") { TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single entity", "[query][join_left][find]") {
auto result = schema.attach<airplane>("airplane") auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} ); .and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok()); REQUIRE(result.is_ok());
auto res = query::create() auto res = query::create()
.table<airplane>("airplane", schema) .table<airplane>("airplane", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -308,7 +308,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
tables_to_drop.emplace("airplane"); tables_to_drop.emplace("airplane");
res = query::create() res = query::create()
.table<flight>("flight", schema) .table<flight>("flight", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -324,7 +324,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
for (const auto &plane: planes) { for (const auto &plane: planes) {
res = query::insert() res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true)) .into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane) .values(*plane)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
@ -347,14 +347,14 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
for (const auto &f: flights) { for (const auto &f: flights) {
res = query::insert() res = query::insert()
.into("flight", column_generator::generate<flight>(schema, true)) .into("flight", column_generator::generate<flight>(repo, true))
.values(*f) .values(*f)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
} }
auto f = query::select(column_generator::generate<flight>(schema, true)) auto f = query::select(column_generator::generate<flight>(repo, true))
.from("flight") .from("flight")
.fetch_one(db); .fetch_one(db);
REQUIRE(f.is_ok()); REQUIRE(f.is_ok());
@ -384,12 +384,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
} }
TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship", "[query][join][many_to_many]") { TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship", "[query][join][many_to_many]") {
auto result = schema.attach<recipe>("recipes") auto result = repo.attach<recipe>("recipes")
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } ) .and_then( [this] { return repo.attach<ingredient>("ingredients"); } )
.and_then( [this] { return schema.attach<recipe_ingredient>("recipe_ingredients"); } ); .and_then( [this] { return repo.attach<recipe_ingredient>("recipe_ingredients"); } );
auto res = query::create() auto res = query::create()
.table<recipe>("recipes", schema) .table<recipe>("recipes", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -398,7 +398,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
tables_to_drop.emplace("recipes"); tables_to_drop.emplace("recipes");
res = query::create() res = query::create()
.table<ingredient>("ingredients", schema) .table<ingredient>("ingredients", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -407,7 +407,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
tables_to_drop.emplace("ingredients"); tables_to_drop.emplace("ingredients");
res = query::create() res = query::create()
.table<recipe_ingredient>("recipe_ingredients", schema) .table<recipe_ingredient>("recipe_ingredients", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 0); REQUIRE(*res == 0);
@ -427,7 +427,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
for (const auto &i: ingredients) { for (const auto &i: ingredients) {
res = query::insert() res = query::insert()
.into("ingredients", column_generator::generate<ingredient>(schema, true)) .into("ingredients", column_generator::generate<ingredient>(repo, true))
.values(i) .values(i)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
@ -442,7 +442,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
for (const auto &r: recipes) { for (const auto &r: recipes) {
res = query::insert() res = query::insert()
.into("recipes", column_generator::generate<recipe>(schema, true)) .into("recipes", column_generator::generate<recipe>(repo, true))
.values(r) .values(r)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
@ -462,7 +462,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
for (const auto &ri: recipe_ingredients) { for (const auto &ri: recipe_ingredients) {
res = query::insert() res = query::insert()
.into("recipe_ingredients", column_generator::generate<recipe_ingredient>(schema, true)) .into("recipe_ingredients", column_generator::generate<recipe_ingredient>(repo, true))
.values({ri.first, ri.second}) .values({ri.first, ri.second})
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());

View File

@ -33,7 +33,7 @@ public:
StatementTestFixture() StatementTestFixture()
{ {
const auto res = query::create() const auto res = query::create()
.table<airplane>("airplane", schema) .table<airplane>("airplane", repo)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
tables_to_drop.emplace("airplane"); tables_to_drop.emplace("airplane");
@ -49,11 +49,11 @@ protected:
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") { TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
using namespace matador::utils; using namespace matador::utils;
REQUIRE(schema.attach<airplane>("airplane")); REQUIRE(repo.attach<airplane>("airplane"));
table ap{"airplane"}; table ap{"airplane"};
SECTION("Insert with prepared statement and placeholder") { SECTION("Insert with prepared statement and placeholder") {
auto stmt = query::insert() auto stmt = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true)) .into("airplane", column_generator::generate<airplane>(repo, true))
.values<airplane>() .values<airplane>()
.prepare(db); .prepare(db);
REQUIRE(stmt.is_ok()); REQUIRE(stmt.is_ok());
@ -65,7 +65,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
stmt->reset(); stmt->reset();
} }
auto result = query::select(column_generator::generate<airplane>(schema, true)) auto result = query::select(column_generator::generate<airplane>(repo, true))
.from(ap) .from(ap)
.fetch_all<airplane>(db); .fetch_all<airplane>(db);
@ -81,14 +81,14 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
SECTION("Select with prepared statement") { SECTION("Select with prepared statement") {
for (const auto &plane: planes) { for (const auto &plane: planes) {
auto res = query::insert() auto res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true)) .into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane) .values(*plane)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
} }
auto stmt = query::select(column_generator::generate<airplane>(schema, true)) auto stmt = query::select(column_generator::generate<airplane>(repo, true))
.from(ap) .from(ap)
.where("brand"_col == _) .where("brand"_col == _)
.prepare(db); .prepare(db);

View File

@ -20,25 +20,25 @@ public:
TypeTraitsTestFixture() { TypeTraitsTestFixture() {
REQUIRE(db.open()); REQUIRE(db.open());
const auto res = query::create() const auto res = query::create()
.table<location>("location", schema) .table<location>("location", repo)
.execute(db); .execute(db);
tables_to_drop.emplace("location"); tables_to_drop.emplace("location");
} }
}; };
TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]") { TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]") {
REQUIRE(schema.attach<location>("location")); REQUIRE(repo.attach<location>("location"));
SECTION("Insert and select with direct execution") { SECTION("Insert and select with direct execution") {
location loc{1, "center", {1, 2, 3}, Color::Black}; location loc{1, "center", {1, 2, 3}, Color::Black};
auto res = query::insert() auto res = query::insert()
.into("location", column_generator::generate<location>(schema, true)) .into("location", column_generator::generate<location>(repo, true))
.values(loc) .values(loc)
.execute(db); .execute(db);
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto result = query::select(column_generator::generate<location>(schema, true)) auto result = query::select(column_generator::generate<location>(repo, true))
.from("location") .from("location")
.fetch_one<location>(db); .fetch_one<location>(db);
@ -54,7 +54,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
location loc{1, "center", {1, 2, 3}, Color::Black}; location loc{1, "center", {1, 2, 3}, Color::Black};
auto stmt = query::insert() auto stmt = query::insert()
.into("location", column_generator::generate<location>(schema, true)) .into("location", column_generator::generate<location>(repo, true))
.values<location>() .values<location>()
.prepare(db); .prepare(db);
REQUIRE(stmt); REQUIRE(stmt);
@ -63,7 +63,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
REQUIRE(res.is_ok()); REQUIRE(res.is_ok());
REQUIRE(*res == 1); REQUIRE(*res == 1);
auto result = query::select(column_generator::generate<location>(schema, true)) auto result = query::select(column_generator::generate<location>(repo, true))
.from("location") .from("location")
.fetch_one<location>(db); .fetch_one<location>(db);

View File

@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "matador/object/attribute_definition_generator.hpp" #include "matador/object/attribute_definition_generator.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "../test/models/product.hpp" #include "../test/models/product.hpp"
#include "../test/models/optional.hpp" #include "../test/models/optional.hpp"
@ -10,7 +10,7 @@ using namespace matador::object;
using namespace matador::utils; using namespace matador::utils;
TEST_CASE("Generate column definitions from object", "[column][definition][generator]") { TEST_CASE("Generate column definitions from object", "[column][definition][generator]") {
schema repo("main"); repository repo("main");
auto result = repo.attach<matador::test::product>("products") auto result = repo.attach<matador::test::product>("products")
.and_then([&repo] { return repo.attach<matador::test::supplier>("supplier"); }) .and_then([&repo] { return repo.attach<matador::test::supplier>("supplier"); })
@ -41,7 +41,7 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
} }
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") { TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
schema repo("main"); repository repo("main");
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo); auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);

View File

@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "../../models/department.hpp" #include "../../models/department.hpp"
@ -28,13 +28,13 @@ struct names {
}; };
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") { TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
const object::schema tree; const object::repository tree;
REQUIRE( tree.empty() ); REQUIRE( tree.empty() );
} }
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") { TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
object::schema tree; object::repository tree;
REQUIRE( tree.empty() ); REQUIRE( tree.empty() );
@ -50,7 +50,7 @@ TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
} }
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") { TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
object::schema tree; object::repository tree;
REQUIRE( tree.empty() ); REQUIRE( tree.empty() );
@ -66,7 +66,7 @@ TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous
} }
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") { TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
object::schema tree; object::repository tree;
REQUIRE( tree.empty() ); REQUIRE( tree.empty() );
@ -75,7 +75,7 @@ TEST_CASE("Test automatic creating of a relation table with foreign key", "[sche
} }
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") { TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
object::schema tree; object::repository tree;
REQUIRE( tree.empty() ); REQUIRE( tree.empty() );

View File

@ -32,7 +32,7 @@ TEST_CASE("Create sql insert for entity with eager has one", "[query][entity][in
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<airplane>("airplanes") auto result = scm.attach<airplane>("airplanes")
.and_then( [&scm] { return scm.attach<flight>("flights"); } ); .and_then( [&scm] { return scm.attach<flight>("flights"); } );
REQUIRE(result); REQUIRE(result);

View File

@ -32,7 +32,7 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<airplane>("airplanes") auto result = scm.attach<airplane>("airplanes")
.and_then( [&scm] { return scm.attach<flight>("flights"); } ); .and_then( [&scm] { return scm.attach<flight>("flights"); } );
REQUIRE(result); REQUIRE(result);
@ -77,7 +77,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<author>("authors") auto result = scm.attach<author>("authors")
.and_then( [&scm] { return scm.attach<book>("books"); } ); .and_then( [&scm] { return scm.attach<book>("books"); } );
REQUIRE(result); REQUIRE(result);
@ -137,7 +137,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<product>("products") auto result = scm.attach<product>("products")
.and_then( [&scm] { return scm.attach<order_details>("order_details"); } ) .and_then( [&scm] { return scm.attach<order_details>("order_details"); } )
.and_then( [&scm] { return scm.attach<supplier>("suppliers"); } ) .and_then( [&scm] { return scm.attach<supplier>("suppliers"); } )
@ -195,7 +195,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<recipe>("recipes") auto result = scm.attach<recipe>("recipes")
.and_then( [&scm] { return scm.attach<ingredient>("ingredients"); } ); .and_then( [&scm] { return scm.attach<ingredient>("ingredients"); } );
// .and_then( [&scm] { return scm.attach<recipe_ingredient>("recipe_ingredients"); } ); // .and_then( [&scm] { return scm.attach<recipe_ingredient>("recipe_ingredients"); } );
@ -240,7 +240,7 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<student>("students") auto result = scm.attach<student>("students")
.and_then( [&scm] { return scm.attach<course>("courses"); } ); .and_then( [&scm] { return scm.attach<course>("courses"); } );
// .and_then( [&scm] { return scm.attach<student_course>("student_courses"); } ); // .and_then( [&scm] { return scm.attach<student_course>("student_courses"); } );
@ -285,7 +285,7 @@ TEST_CASE("Test eager relationship", "[session][eager]") {
using namespace matador::test; using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>()); backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db"); connection db("noop://noop.db");
schema scm("noop"); repository scm("noop");
auto result = scm.attach<department>("departments") auto result = scm.attach<department>("departments")
.and_then( [&scm] { return scm.attach<employee>("employees"); } ); .and_then( [&scm] { return scm.attach<employee>("employees"); } );

View File

@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "matador/sql/column_generator.hpp" #include "matador/sql/column_generator.hpp"
#include "matador/object/schema.hpp" #include "matador/object/repository.hpp"
#include "../test/models/product.hpp" #include "../test/models/product.hpp"
#include "../test/models/order.hpp" #include "../test/models/order.hpp"
@ -14,7 +14,7 @@ using namespace matador::object;
TEST_CASE("Generate columns from object", "[column][generator]") { TEST_CASE("Generate columns from object", "[column][generator]") {
using namespace matador::test; using namespace matador::test;
schema s("main"); repository s("main");
auto result = s.attach<product>("product"); auto result = s.attach<product>("product");
REQUIRE( result ); REQUIRE( result );
@ -41,7 +41,7 @@ TEST_CASE("Generate columns from object", "[column][generator]") {
TEST_CASE("Generate columns for object with has many relation", "[column][generator][relation]") { TEST_CASE("Generate columns for object with has many relation", "[column][generator][relation]") {
using namespace matador::test; using namespace matador::test;
schema s("main"); repository s("main");
auto result = s.attach<supplier>("supplier") auto result = s.attach<supplier>("supplier")
.and_then( [&s] { return s.attach<category>("categories"); } ) .and_then( [&s] { return s.attach<category>("categories"); } )
.and_then( [&s] { return s.attach<order_details>("order_details"); } ) .and_then( [&s] { return s.attach<order_details>("order_details"); } )
@ -81,7 +81,7 @@ TEST_CASE("Generate columns for object with has many relation", "[column][genera
TEST_CASE("Generate columns for object with eager foreign key relation", "[column][generator][eager]") { TEST_CASE("Generate columns for object with eager foreign key relation", "[column][generator][eager]") {
using namespace matador::test; using namespace matador::test;
schema s("main"); repository s("main");
auto result = s.attach<book>("books") auto result = s.attach<book>("books")
.and_then( [&s] { return s.attach<author>("authors"); } ); .and_then( [&s] { return s.attach<author>("authors"); } );
REQUIRE(result); REQUIRE(result);