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/object/object_ptr.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include "matador/utils/access.hpp"
#include "matador/utils/default_type_traits.hpp"
@ -161,7 +161,7 @@ int main() {
const std::string env_var{"MATADOR_BACKENDS_PATH"};
std::string dns{"sqlite://demo.db"};
schema s( "main" );
repository s( "main" );
auto result = s.attach<author>( "authors" ).and_then( [&s] {
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"
@ -133,82 +133,82 @@ int main() {
{
// 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
object::schema schema;
object::repository repo;
auto result = schema.attach<person_repo>("person_repo")
.and_then([&schema] { return schema.attach<person>("persons"); });
auto result = repo.attach<person_repo>("person_repo")
.and_then([&repo] { return repo.attach<person>("persons"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// has_many with foreign without belongs_to
object::schema schema;
object::repository repo;
auto result = schema.attach<person>("persons")
.and_then([&schema] { return schema.attach<person_repo>("person_repo"); });
auto result = repo.attach<person>("persons")
.and_then([&repo] { return repo.attach<person_repo>("person_repo"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// has_many to belongs_to
object::schema schema;
object::repository repo;
auto result = schema.attach<author>("authors")
.and_then([&schema] { return schema.attach<book>("books"); });
auto result = repo.attach<author>("authors")
.and_then([&repo] { return repo.attach<book>("books"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// belongs_to to has_many
object::schema schema;
object::repository repo;
auto result = schema.attach<book>("books")
.and_then([&schema] { return schema.attach<author>("authors"); });
auto result = repo.attach<book>("books")
.and_then([&repo] { return repo.attach<author>("authors"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// has_many_to_many (with join columns first)
object::schema schema;
object::repository repo;
auto result = schema.attach<demo::ingredient>("ingredients")
.and_then([&schema] { return schema.attach<recipe>("recipes"); });
auto result = repo.attach<demo::ingredient>("ingredients")
.and_then([&repo] { return repo.attach<recipe>("recipes"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// has_many_to_many (with join columns last)
object::schema schema;
object::repository repo;
auto result = schema.attach<demo::recipe>("recipes")
.and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
auto result = repo.attach<demo::recipe>("recipes")
.and_then([&repo] { return repo.attach<ingredient>("ingredients"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// belongs_to to has_one
object::schema schema;
object::repository repo;
auto result = schema.attach<profile>("profiles")
.and_then([&schema] { return schema.attach<user>("users"); });
auto result = repo.attach<profile>("profiles")
.and_then([&repo] { return repo.attach<user>("users"); });
schema.dump(std::cout);
repo.dump(std::cout);
}
{
// has_one to belongs_to
object::schema schema;
object::repository repo;
auto result = schema.attach<user>("users")
.and_then([&schema] { return schema.attach<profile>("profiles"); });
auto result = repo.attach<user>("users")
.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 "matador/utils/default_type_traits.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.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 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");
admin_schema.create(pool);
admin_schema.drop(pool);
auto result = repo.attach<admin::CollectionCenter>("collection_centers");
repo.create(pool);
repo.drop(pool);
orm::session ses(pool);

View File

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

View File

@ -11,7 +11,7 @@
namespace matador::object {
class schema_node;
class repository_node;
class relation_endpoint;
class basic_object_info {
@ -49,12 +49,12 @@ public:
[[nodiscard]] bool endpoints_empty() const;
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<schema_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, 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);
basic_object_info(std::shared_ptr<repository_node> node, object_definition &&definition);
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_;
std::optional<utils::identifier> identifier_;
std::shared_ptr<attribute_definition> pk_column_;

View File

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

View File

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

View File

@ -5,26 +5,26 @@
#include "matador/object/object_definition.hpp"
namespace matador::object {
class schema_node;
class repository_node;
template<typename Type>
class object_info final : public basic_object_info {
public:
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)
: basic_object_info(node, {}, ref_column, {})
, 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,
const std::shared_ptr<attribute_definition> &ref_column,
object_definition &&definition)
: basic_object_info(node, std::move(pk), ref_column, std::move(definition))
, 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,
const std::shared_ptr<attribute_definition> &ref_column,
object_definition &&definition,
@ -32,7 +32,7 @@ public:
: basic_object_info(node, std::move(pk), ref_column, std::move(definition))
, 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,
create_func&& creator)
: basic_object_info(node, std::move(definition))

View File

@ -1,11 +1,11 @@
#ifndef 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/join_columns_collector.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"
@ -94,13 +94,13 @@ private:
template<typename Type>
class relation_completer final {
private:
using node_ptr = std::shared_ptr<schema_node>;
using node_ptr = std::shared_ptr<repository_node>;
public:
using endpoint_ptr = std::shared_ptr<relation_endpoint>;
static void complete(const std::shared_ptr<schema_node> &node) {
internal::shadow_schema shadow(node->schema_);
static void complete(const std::shared_ptr<repository_node> &node) {
internal::shadow_repository shadow(node->repo_);
relation_completer completer(shadow);
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);
private:
explicit relation_completer(internal::shadow_schema &shadow)
explicit relation_completer(internal::shadow_repository &shadow)
: schema_(shadow)
, 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);
Type obj;
@ -150,7 +150,7 @@ private:
private:
std::stack<node_ptr> nodes_;
internal::shadow_schema &schema_;
internal::shadow_repository &schema_;
logger::logger log_;
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
// 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);
result = schema_node::make_relation_node<relation_value_type>(
schema_.schema(), id, [join_column] {
result = repository_node::make_relation_node<relation_value_type>(
schema_.repo(), id, [join_column] {
return std::make_unique<relation_value_type>("id", join_column);
});
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 relation_value_type = many_to_relation<Type, value_type>;
const auto result = schema_node::make_relation_node<relation_value_type>(
schema_.schema(), id, [join_column] {
const auto result = repository_node::make_relation_node<relation_value_type>(
schema_.repo(), id, [join_column] {
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);
};
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) {
// Todo: throw internal error
return;

View File

@ -8,7 +8,7 @@
namespace matador::object {
class schema_node;
class repository_node;
enum class relation_type : uint8_t {
BELONGS_TO,
@ -24,14 +24,14 @@ static const utils::enum_mapper<relation_type> relation_type_enum({
class relation_endpoint {
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]] relation_type type() 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_many() const;
@ -46,7 +46,7 @@ private:
std::string field_name_;
relation_type type_;
std::shared_ptr<schema_node> node_;
std::shared_ptr<repository_node> node_;
std::shared_ptr<relation_endpoint> foreign_endpoint_;
};

View File

@ -6,8 +6,8 @@
#include "matador/object/error_code.hpp"
#include "matador/object/foreign_node_completer.hpp"
#include "matador/object/relation_completer.hpp"
#include "matador/object/schema_node.hpp"
#include "matador/object/schema_node_iterator.hpp"
#include "matador/object/repository_node.hpp"
#include "matador/object/repository_node_iterator.hpp"
#include "matador/utils/result.hpp"
#include "matador/utils/error.hpp"
@ -20,27 +20,27 @@
namespace matador::object {
namespace internal {
class shadow_schema;
class shadow_repository;
}
utils::error make_error(error_code ec, const std::string &msg);
class schema {
class repository {
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
*/
explicit schema(std::string name = "");
explicit repository(std::string name = "");
template<typename Type>
[[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 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) {
return utils::failure(result.err());
}
@ -172,12 +172,12 @@ private:
void remove_node(const node_ptr &node);
private:
friend class internal::shadow_schema;
friend class schema_node;
friend class internal::shadow_repository;
friend class repository_node;
friend class attribute_definition_generator;
std::string name_;
std::shared_ptr<schema_node> root_;
std::shared_ptr<repository_node> root_;
t_node_map nodes_by_name_;
t_type_index_node_map nodes_by_type_;

View File

@ -10,15 +10,15 @@
namespace matador::object {
class basic_object_info;
class schema;
class repository;
class schema_node final {
class repository_node final {
public:
using node_ptr = std::shared_ptr<schema_node>;
using node_ptr = std::shared_ptr<repository_node>;
template < typename Type >
static std::shared_ptr<schema_node> make_node(object::schema& tree, const std::string& name) {
auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, typeid(Type)));
static std::shared_ptr<repository_node> make_node(object::repository& tree, const std::string& name) {
auto node = std::shared_ptr<repository_node>(new repository_node(tree, name, typeid(Type)));
primary_key_resolver resolver;
auto pk_info = resolver.resolve<Type>();
@ -36,7 +36,7 @@ public:
}
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));
if (!result) {
return result;
@ -53,13 +53,13 @@ public:
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;
schema_node(schema_node&& other) = default;
schema_node& operator=(const schema_node& other) = delete;
schema_node& operator=(schema_node&& other) = delete;
~schema_node() = default;
repository_node(const repository_node& other) = delete;
repository_node(repository_node&& other) = default;
repository_node& operator=(const repository_node& other) = delete;
repository_node& operator=(repository_node&& other) = delete;
~repository_node() = default;
[[nodiscard]] std::string name() const;
[[nodiscard]] std::type_index type_index() const;
@ -76,39 +76,39 @@ public:
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;
private:
explicit schema_node(object::schema& tree);
schema_node(object::schema& tree, const std::type_index& ti);
schema_node(object::schema& tree, std::string name, const std::type_index& ti);
explicit repository_node(object::repository& tree);
repository_node(object::repository& tree, const std::type_index& ti);
repository_node(object::repository& tree, std::string name, const std::type_index& ti);
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,
const std::string& name,
const primary_key_info& pk_info,
object::schema& tree);
object::repository& tree);
private:
friend class schema;
friend class repository;
template<typename Type>
friend class relation_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::unique_ptr<basic_object_info> info_;
std::shared_ptr<schema_node> parent_;
std::shared_ptr<schema_node> previous_sibling_;
std::shared_ptr<schema_node> next_sibling_;
std::shared_ptr<schema_node> first_child_;
std::shared_ptr<schema_node> last_child_;
std::shared_ptr<repository_node> parent_;
std::shared_ptr<repository_node> previous_sibling_;
std::shared_ptr<repository_node> next_sibling_;
std::shared_ptr<repository_node> first_child_;
std::shared_ptr<repository_node> last_child_;
std::string name_;
size_t depth_{0};

View File

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

View File

@ -15,7 +15,7 @@
#include "matador/object/object_ptr.hpp"
#include "matador/object/object_definition.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include <unordered_map>
@ -181,7 +181,7 @@ private:
mutable sql::statement_cache cache_;
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_;
};

View File

@ -6,7 +6,7 @@
#include "matador/query/condition.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/primary_key_attribute.hpp"
@ -38,7 +38,7 @@ private:
class session_insert_builder final {
public:
explicit session_insert_builder(const object::schema &scm)
explicit session_insert_builder(const object::repository &scm)
: schema_(scm) {
}
@ -123,7 +123,7 @@ private:
std::stack<table_info> table_info_stack_;
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_;
};
}

View File

@ -10,7 +10,7 @@
#include "matador/sql/statement.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/result.hpp"
@ -32,7 +32,7 @@ struct entity_query_data {
class session_query_builder final {
public:
session_query_builder(const object::schema &scm, sql::executor &exec)
session_query_builder(const object::repository &scm, sql::executor &exec)
: schema_(scm)
, executor_(exec){}
@ -247,7 +247,7 @@ private:
std::stack<table_info> table_info_stack_;
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_;
unsigned int column_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, const std::vector<object::attribute_definition> &columns);
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));
}
};

View File

@ -14,7 +14,7 @@ public:
query_insert_intermediate();
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));
}
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(std::vector<sql::column> columns, std::initializer_list<sql::column> additional_columns);
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));
}
[[nodiscard]] static query_insert_intermediate insert();

View File

@ -8,7 +8,7 @@
#include "matador/sql/column.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include <string>
#include <vector>
@ -20,14 +20,14 @@ class column_generator
{
private:
column_generator(std::vector<column> &column_infos,
const object::schema &ts,
const object::repository &ts,
const std::string &table_name,
bool force_lazy,
bool has_many_to_many = false);
public:
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>();
if (!info) {
return {};
@ -40,7 +40,7 @@ public:
}
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>();
if (!info) {
return {};
@ -143,7 +143,7 @@ private:
std::stack<std::string> table_name_stack_;
std::vector<column> &column_infos_;
std::unordered_set<std::string> seen_tables;
const object::schema &table_schema_;
const object::repository &table_schema_;
int column_index{0};
bool force_lazy_{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/error_code.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/object_definition.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/relation_completer.hpp
../../include/matador/object/relation_endpoint.hpp
../../include/matador/object/schema.hpp
../../include/matador/object/schema_node.hpp
../../include/matador/object/schema_node_iterator.hpp
../../include/matador/object/repository.hpp
../../include/matador/object/repository_node.hpp
../../include/matador/object/repository_node_iterator.hpp
../../include/matador/sql/statement_cache.hpp
../../include/matador/utils/access.hpp
../../include/matador/utils/attribute_reader.hpp
@ -80,12 +80,12 @@ add_library(matador-core STATIC
object/basic_object_info.cpp
object/error_code.cpp
object/foreign_node_completer.cpp
object/internal/shadow_schema.cpp
object/internal/shadow_repository.cpp
object/object_definition.cpp
object/relation_endpoint.cpp
object/schema.cpp
object/schema_node.cpp
object/schema_node_iterator.cpp
object/repository.cpp
object/repository_node.cpp
object/repository_node_iterator.cpp
utils/default_type_traits.cpp
utils/error.cpp
utils/errors.cpp

View File

@ -1,9 +1,9 @@
#include "matador/object/attribute_definition_generator.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
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)
, 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 {
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/schema_node.hpp"
#include "matador/object/repository_node.hpp"
#include <algorithm>
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,
const std::shared_ptr<attribute_definition> &pk_column,
object_definition &&definition)
@ -15,7 +15,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
, 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,
const std::shared_ptr<attribute_definition> &pk_column)
: node_(std::move(node))
@ -23,7 +23,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
, 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)
: node_(std::move(node))
, definition_(std::move(definition)) {}

View File

@ -1,11 +1,11 @@
#include "matador/object/foreign_node_completer.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include "matador/logger/logger.hpp"
namespace matador::object {
foreign_node_completer::foreign_node_completer(internal::shadow_schema &shadow)
: schema_(shadow)
foreign_node_completer::foreign_node_completer(internal::shadow_repository &shadow)
: repo_(shadow)
, 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/schema_node.hpp"
#include "matador/object/repository_node.hpp"
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))
, type_(type)
, node_(node) {
@ -21,11 +21,11 @@ std::string relation_endpoint::type_name() const {
return relation_type_enum.to_string(type_);
}
const schema_node &relation_endpoint::node() const {
const repository_node &relation_endpoint::node() const {
return *node_;
}
std::shared_ptr<schema_node> relation_endpoint::node_ptr() const {
std::shared_ptr<repository_node> relation_endpoint::node_ptr() const {
return node_;
}

View File

@ -1,23 +1,23 @@
#include <utility>
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
namespace matador::object {
utils::error make_error(const error_code ec, const std::string &msg) {
return utils::error(ec, msg);
}
schema::schema(std::string name)
repository::repository(std::string name)
: name_(std::move(name))
, root_(schema_node::make_null_node(*this))
, root_(repository_node::make_null_node(*this))
, log_(logger::create_logger("schema")) {
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->last_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<repository_node>(new repository_node(*this));
root_->first_child_->next_sibling_ = root_->last_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());
remove_node(node);
@ -25,35 +25,35 @@ utils::result<void, utils::error> schema::detach(const node_ptr &node) {
return utils::ok<void>();
}
schema::const_iterator schema::begin() const {
repository::const_iterator repository::begin() const {
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_);
}
bool schema::empty() const {
bool repository::empty() const {
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()));
}
std::string schema::name() const {
std::string repository::name() const {
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;
}
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;
}
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);
if (result) {
return utils::ok((*result)->info().reference_column());
@ -62,14 +62,14 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::refer
return utils::failure(result.err());
}
void schema::dump(std::ostream &os) const {
void repository::dump(std::ostream &os) const {
for (const auto &node : *this) {
dump(os, node);
}
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";
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")";
@ -81,7 +81,7 @@ void schema::dump( std::ostream& os, const node_ptr& node ) {
}
}
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) {
if (has_node(node)) {
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
@ -127,7 +127,7 @@ utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::sha
// 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
const auto i = nodes_by_name_.find(name);
if (i == nodes_by_name_.end()) {
@ -136,7 +136,7 @@ utils::result<schema::node_ptr, utils::error> schema::find_node(const std::strin
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);
if (i == nodes_by_type_.end()) {
return utils::failure(make_error(error_code::NodeNotFound,
@ -145,7 +145,7 @@ utils::result<schema::node_ptr, utils::error> schema::find_node(const std::type_
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->previous_sibling_ = parent->last_child_->previous_sibling_;
child->next_sibling_ = parent->last_child_;
@ -161,7 +161,7 @@ void schema::insert_node(const node_ptr &parent, const node_ptr &child) {
// child->depth = depth + 1;
}
void schema::remove_node(const node_ptr &node) {
void repository::remove_node(const node_ptr &node) {
auto next = node->next();
std::stack<node_ptr> nodes_to_remove;
@ -188,15 +188,15 @@ void schema::remove_node(const node_ptr &node) {
}
}
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;
}
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;
}
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;
}
} // namespace matador::object

View File

@ -1,62 +1,62 @@
#include <utility>
#include "matador/object/schema.hpp"
#include "matador/object/schema_node.hpp"
#include "matador/object/repository.hpp"
#include "matador/object/repository_node.hpp"
namespace matador::object {
schema_node::schema_node(object::schema &tree)
: schema_(tree)
repository_node::repository_node(object::repository &tree)
: repo_(tree)
, type_index_(typeid(detail::null_type)){
}
schema_node::schema_node(object::schema &tree, const std::type_index& ti)
: schema_(tree)
repository_node::repository_node(object::repository &tree, const std::type_index& ti)
: repo_(tree)
, type_index_(ti) {
}
schema_node::schema_node(object::schema &tree, std::string name, const std::type_index& ti)
: schema_(tree)
repository_node::repository_node(object::repository &tree, std::string name, const std::type_index& ti)
: repo_(tree)
, type_index_(ti)
, first_child_(std::shared_ptr<schema_node>(new schema_node(tree)))
, last_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<repository_node>(new repository_node(tree)))
, name_(std::move(name)) {
first_child_->next_sibling_ = last_child_;
last_child_->previous_sibling_ = first_child_;
}
std::shared_ptr<schema_node> schema_node::make_null_node(object::schema &tree) {
auto node = std::shared_ptr<schema_node>(new schema_node(tree));
std::shared_ptr<repository_node> repository_node::make_null_node(object::repository &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>{});
return node;
}
std::string schema_node::name() const {
std::string repository_node::name() const {
return name_;
}
std::type_index schema_node::type_index() const {
std::type_index repository_node::type_index() const {
return type_index_;
}
const basic_object_info &schema_node::info() const {
const basic_object_info &repository_node::info() const {
return *info_;
}
void schema_node::update_name(const std::string& name) {
void repository_node::update_name(const std::string& name) {
name_ = name;
info_->reference_column()->table_name(name);
}
const object::schema& schema_node::schema() const {
return schema_;
const object::repository& repository_node::schema() const {
return repo_;
}
bool schema_node::has_children() const {
bool repository_node::has_children() const {
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 don't iterate over the siblings)
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_;
}
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
// as our next iterator. then we check if there
// 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_;
}
void schema_node::unlink() {
void repository_node::unlink() {
previous_sibling_->next_sibling_ = next_sibling_;
next_sibling_->previous_sibling_ = previous_sibling_;
next_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) {
const auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, 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<repository_node>(new repository_node(tree, name, ti));
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);
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);

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)
: cache_(ctx.bus, ctx.pool, ctx.cache_size)
, 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 {
// Step 1: Build 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 (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#ifndef MATADOR_QUERY_FIXTURE_HPP
#define MATADOR_QUERY_FIXTURE_HPP
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include "matador/sql/connection.hpp"
@ -22,7 +22,7 @@ public:
protected:
sql::connection db;
std::stack <std::string> tables_to_drop;
object::schema schema;
object::repository repo;
private:
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;
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()
.table<matador::test::person>("person", schema)
.table<matador::test::person>("person", repo)
.prepare(db);
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]") {
using namespace matador::test;
REQUIRE(schema.attach<person>("person"));
REQUIRE(repo.attach<person>("person"));
auto stmt = query::create()
.table<person>("person", schema)
.table<person>("person", repo)
.prepare(db);
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}};
stmt = query::insert()
.into<person>("person", schema)
.into<person>("person", repo)
.values<person>()
.prepare(db);
REQUIRE(stmt);
@ -69,7 +69,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
auto row = query::select<person>(schema)
auto row = query::select<person>(repo)
.from("person")
.fetch_one<person>(db);
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::utils;
REQUIRE(schema.attach<matador::test::person>("person"));
REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create()
.table<matador::test::person>("person", schema)
.table<matador::test::person>("person", repo)
.prepare(db);
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}};
stmt = query::insert()
.into<person>("person", schema)
.into<person>("person", repo)
.values<person>()
.prepare(db);
REQUIRE(stmt);
@ -111,7 +111,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
auto row = query::select<person>(schema)
auto row = query::select<person>(repo)
.from("person")
.fetch_one<person>(db);
REQUIRE(row.is_ok());
@ -136,7 +136,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
row = query::select<person>(schema)
row = query::select<person>(repo)
.from("person")
.fetch_one<person>(db);
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]") {
using namespace matador::test;
REQUIRE(schema.attach<matador::test::person>("person"));
REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create()
.table<matador::test::person>("person", schema)
.table<matador::test::person>("person", repo)
.prepare(db);
REQUIRE(stmt);
@ -165,7 +165,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
check_table_exists("person");
stmt = query::insert()
.into<person>("person", schema)
.into<person>("person", repo)
.values<person>()
.prepare(db);
REQUIRE(stmt);
@ -185,7 +185,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
stmt->reset();
}
auto select_stmt = query::select<person>(schema)
auto select_stmt = query::select<person>(repo)
.from("person")
.where("name"_col == matador::utils::_)
.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]") {
using namespace matador::test;
REQUIRE(schema.attach<matador::test::person>("person"));
REQUIRE(repo.attach<matador::test::person>("person"));
auto stmt = query::create()
.table<matador::test::person>("person", schema)
.table<matador::test::person>("person", repo)
.prepare(db);
REQUIRE(stmt);
@ -252,7 +252,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
check_table_exists("person");
stmt = query::insert()
.into<person>("person", schema)
.into<person>("person", repo)
.values<person>()
.prepare(db);
REQUIRE(stmt);
@ -272,7 +272,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
stmt->reset();
}
stmt = query::select<person>(schema)
stmt = query::select<person>(repo)
.from("person")
.prepare(db);
REQUIRE(stmt);

View File

@ -20,12 +20,12 @@ using namespace matador::sql;
using namespace matador::test;
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query][foreign][relation]") {
auto result = schema.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} );
auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto res = query::create()
.table<airplane>("airplane", schema)
.table<airplane>("airplane", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -34,7 +34,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
tables_to_drop.emplace("airplane");
res = query::create()
.table<flight>("flight", schema)
.table<flight>("flight", repo)
.execute(db);
REQUIRE(res.is_ok());
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]") {
REQUIRE(schema.attach<person>("person"));
REQUIRE(repo.attach<person>("person"));
auto res = query::create()
.table<person>("person", schema)
.table<person>("person", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -58,14 +58,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
george.image.emplace_back(37);
res = query::insert()
.into("person", column_generator::generate<person>(schema, true))
.into("person", column_generator::generate<person>(repo, true))
.values(george)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
// 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")
.where("id"_col == 7)
.fetch_all(db);
@ -85,7 +85,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
}
// 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")
.where("id"_col == 7)
.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]") {
auto result = schema.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} );
auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto res = query::create()
.table<airplane>("airplane", schema)
.table<airplane>("airplane", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -155,7 +155,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
tables_to_drop.emplace("airplane");
res = query::create()
.table<flight>("flight", schema)
.table<flight>("flight", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -171,7 +171,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
for (const auto &plane: planes) {
res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true))
.into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane)
.execute(db);
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"};
res = query::insert()
.into("flight", column_generator::generate<flight>(schema, true))
.into("flight", column_generator::generate<flight>(repo, true))
.values(f4711)
.execute(db);
REQUIRE(res.is_ok());
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")
.fetch_one(db);
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]") {
auto result = schema.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} );
auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto res = query::create()
.table<airplane>("airplane", schema)
.table<airplane>("airplane", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -218,7 +218,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
tables_to_drop.emplace("airplane");
res = query::create()
.table<flight>("flight", schema)
.table<flight>("flight", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -234,7 +234,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
for (const auto &plane: planes) {
res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true))
.into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane)
.execute(db);
REQUIRE(res.is_ok());
@ -262,7 +262,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
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")
.fetch_one(db);
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]") {
auto result = schema.attach<airplane>("airplane")
.and_then( [this] { return schema.attach<flight>("flight");} );
auto result = repo.attach<airplane>("airplane")
.and_then( [this] { return repo.attach<flight>("flight");} );
REQUIRE(result.is_ok());
auto res = query::create()
.table<airplane>("airplane", schema)
.table<airplane>("airplane", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -308,7 +308,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
tables_to_drop.emplace("airplane");
res = query::create()
.table<flight>("flight", schema)
.table<flight>("flight", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -324,7 +324,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
for (const auto &plane: planes) {
res = query::insert()
.into("airplane", column_generator::generate<airplane>(schema, true))
.into("airplane", column_generator::generate<airplane>(repo, true))
.values(*plane)
.execute(db);
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) {
res = query::insert()
.into("flight", column_generator::generate<flight>(schema, true))
.into("flight", column_generator::generate<flight>(repo, true))
.values(*f)
.execute(db);
REQUIRE(res.is_ok());
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")
.fetch_one(db);
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]") {
auto result = schema.attach<recipe>("recipes")
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } )
.and_then( [this] { return schema.attach<recipe_ingredient>("recipe_ingredients"); } );
auto result = repo.attach<recipe>("recipes")
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } )
.and_then( [this] { return repo.attach<recipe_ingredient>("recipe_ingredients"); } );
auto res = query::create()
.table<recipe>("recipes", schema)
.table<recipe>("recipes", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -398,7 +398,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
tables_to_drop.emplace("recipes");
res = query::create()
.table<ingredient>("ingredients", schema)
.table<ingredient>("ingredients", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -407,7 +407,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
tables_to_drop.emplace("ingredients");
res = query::create()
.table<recipe_ingredient>("recipe_ingredients", schema)
.table<recipe_ingredient>("recipe_ingredients", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@ -427,7 +427,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
for (const auto &i: ingredients) {
res = query::insert()
.into("ingredients", column_generator::generate<ingredient>(schema, true))
.into("ingredients", column_generator::generate<ingredient>(repo, true))
.values(i)
.execute(db);
REQUIRE(res.is_ok());
@ -442,7 +442,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
for (const auto &r: recipes) {
res = query::insert()
.into("recipes", column_generator::generate<recipe>(schema, true))
.into("recipes", column_generator::generate<recipe>(repo, true))
.values(r)
.execute(db);
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) {
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})
.execute(db);
REQUIRE(res.is_ok());

View File

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

View File

@ -20,25 +20,25 @@ public:
TypeTraitsTestFixture() {
REQUIRE(db.open());
const auto res = query::create()
.table<location>("location", schema)
.table<location>("location", repo)
.execute(db);
tables_to_drop.emplace("location");
}
};
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") {
location loc{1, "center", {1, 2, 3}, Color::Black};
auto res = query::insert()
.into("location", column_generator::generate<location>(schema, true))
.into("location", column_generator::generate<location>(repo, true))
.values(loc)
.execute(db);
REQUIRE(res.is_ok());
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")
.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};
auto stmt = query::insert()
.into("location", column_generator::generate<location>(schema, true))
.into("location", column_generator::generate<location>(repo, true))
.values<location>()
.prepare(db);
REQUIRE(stmt);
@ -63,7 +63,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
REQUIRE(res.is_ok());
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")
.fetch_one<location>(db);

View File

@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.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/optional.hpp"
@ -10,7 +10,7 @@ using namespace matador::object;
using namespace matador::utils;
TEST_CASE("Generate column definitions from object", "[column][definition][generator]") {
schema repo("main");
repository repo("main");
auto result = repo.attach<matador::test::product>("products")
.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]") {
schema repo("main");
repository repo("main");
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);

View File

@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp>
#include "matador/object/schema.hpp"
#include "matador/object/repository.hpp"
#include "../../models/department.hpp"
@ -28,13 +28,13 @@ struct names {
};
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
const object::schema tree;
const object::repository tree;
REQUIRE( tree.empty() );
}
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
object::schema tree;
object::repository tree;
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]") {
object::schema tree;
object::repository tree;
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]") {
object::schema tree;
object::repository tree;
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]") {
object::schema tree;
object::repository tree;
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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<airplane>("airplanes")
.and_then( [&scm] { return scm.attach<flight>("flights"); } );
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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<airplane>("airplanes")
.and_then( [&scm] { return scm.attach<flight>("flights"); } );
REQUIRE(result);
@ -77,7 +77,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
using namespace matador::test;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<author>("authors")
.and_then( [&scm] { return scm.attach<book>("books"); } );
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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<product>("products")
.and_then( [&scm] { return scm.attach<order_details>("order_details"); } )
.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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<recipe>("recipes")
.and_then( [&scm] { return scm.attach<ingredient>("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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<student>("students")
.and_then( [&scm] { return scm.attach<course>("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;
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
connection db("noop://noop.db");
schema scm("noop");
repository scm("noop");
auto result = scm.attach<department>("departments")
.and_then( [&scm] { return scm.attach<employee>("employees"); } );

View File

@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.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/order.hpp"
@ -14,7 +14,7 @@ using namespace matador::object;
TEST_CASE("Generate columns from object", "[column][generator]") {
using namespace matador::test;
schema s("main");
repository s("main");
auto result = s.attach<product>("product");
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]") {
using namespace matador::test;
schema s("main");
repository s("main");
auto result = s.attach<supplier>("supplier")
.and_then( [&s] { return s.attach<category>("categories"); } )
.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]") {
using namespace matador::test;
schema s("main");
repository s("main");
auto result = s.attach<book>("books")
.and_then( [&s] { return s.attach<author>("authors"); } );
REQUIRE(result);