fixed some repository-related tests
This commit is contained in:
parent
5d2d6d4a30
commit
12905e3df3
|
|
@ -2,8 +2,8 @@ CPMAddPackage("gh:catchorg/Catch2@3.7.1")
|
|||
|
||||
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||
|
||||
set(POSTGRES_CONNECTION_STRING "postgres://news:news@127.0.0.1:15432/matador")
|
||||
#set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:15432/matador")
|
||||
#set(POSTGRES_CONNECTION_STRING "postgres://news:news@127.0.0.1:15432/matador")
|
||||
set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:15442/matador")
|
||||
|
||||
configure_file(Connection.hpp.in ${PROJECT_BINARY_DIR}/backends/postgres/test/connection.hpp @ONLY IMMEDIATE)
|
||||
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ private:
|
|||
}
|
||||
|
||||
template<typename Type>
|
||||
void attach_node() {
|
||||
void attach_node(const std::string &name = "") {
|
||||
if (repo_.contains(typeid(Type))) {
|
||||
return;
|
||||
}
|
||||
const auto node = repository_node::make_node<Type>(repo_.repo(), "");
|
||||
const auto node = repository_node::make_node<Type>(repo_.repo(), name);
|
||||
if (auto result = repo_.attach_node(node)) {
|
||||
complete<Type>(result.value());
|
||||
}
|
||||
|
|
@ -101,13 +101,13 @@ void foreign_node_completer::on_has_many( const char* /*id*/, CollectionType&, c
|
|||
}
|
||||
|
||||
template<class CollectionType>
|
||||
void foreign_node_completer::on_has_many_to_many( const char* /*id*/, CollectionType& /*collection*/, const char* /*join_column*/, const char* /*inverse_join_column*/, const utils::foreign_attributes& /*attr*/ ) {
|
||||
attach_node<typename CollectionType::value_type::value_type>();
|
||||
void foreign_node_completer::on_has_many_to_many( const char* id, CollectionType& /*collection*/, const char* /*join_column*/, const char* /*inverse_join_column*/, const utils::foreign_attributes& /*attr*/ ) {
|
||||
attach_node<typename CollectionType::value_type::value_type>(/*id*/);
|
||||
}
|
||||
|
||||
template<class CollectionType>
|
||||
void foreign_node_completer::on_has_many_to_many( const char* /*id*/, CollectionType& /*collection*/, const utils::foreign_attributes& /*attr*/ ) {
|
||||
attach_node<typename CollectionType::value_type::value_type>();
|
||||
void foreign_node_completer::on_has_many_to_many( const char* id, CollectionType& /*collection*/, const utils::foreign_attributes& /*attr*/ ) {
|
||||
attach_node<typename CollectionType::value_type::value_type>(/*id*/);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ public:
|
|||
} else if (!has_node(name)) {
|
||||
it->second->update_name(name);
|
||||
nodes_by_name_[name] = it->second;
|
||||
if (const auto i = nodes_by_name_.find(""); i != nodes_by_name_.end()) {
|
||||
nodes_by_name_.erase(i);
|
||||
}
|
||||
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());
|
||||
} else {
|
||||
|
|
@ -135,6 +138,8 @@ public:
|
|||
return utils::ok(result.value()->info<Type>());
|
||||
}
|
||||
|
||||
[[nodiscard]] utils::result<basic_object_info_ref, utils::error> basic_info(const std::string &name) const;
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<basic_object_info_ref, utils::error> basic_info() const {
|
||||
auto result = find_node(std::type_index(typeid(Type)));
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ public:
|
|||
return columns;
|
||||
}
|
||||
|
||||
static std::vector<column> generate(const object::repository &scm, const std::string &name, bool force_lazy = false);
|
||||
|
||||
template < class Type >
|
||||
static std::vector<column> generate_has_many_to_many(const object::repository &scm, const bool force_lazy = false) {
|
||||
const auto info = scm.info<Type>();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace matador::sql {
|
|||
class connection_pool;
|
||||
|
||||
struct identifiable_connection {
|
||||
identifiable_connection(size_t id, connection conn);
|
||||
identifiable_connection(size_t id, connection &&conn);
|
||||
size_t id{};
|
||||
connection conn;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,6 +53,15 @@ bool repository::contains( const std::type_index& index ) const {
|
|||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
utils::result<basic_object_info_ref, utils::error> repository::basic_info( const std::string& name ) const {
|
||||
auto result = find_node(name);
|
||||
if (!result) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
return utils::ok(basic_object_info_ref{result.value()->info()});
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,19 @@ column_generator::column_generator(std::vector<column> &column_infos,
|
|||
seen_tables.insert(table_name);
|
||||
}
|
||||
|
||||
std::vector<column> column_generator::generate( const object::repository& scm, const std::string& name, bool force_lazy ) {
|
||||
const auto info = scm.basic_info(name);
|
||||
if (!info) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<column> columns;
|
||||
for (const auto attr : info.value().get().definition()) {
|
||||
columns.push_back(column{attr.name()});
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
void column_generator::on_revision(const char *id, unsigned long long int &)
|
||||
{
|
||||
if (has_many_to_many_) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <thread>
|
||||
|
||||
namespace matador::sql {
|
||||
identifiable_connection::identifiable_connection(const size_t id, connection conn)
|
||||
identifiable_connection::identifiable_connection(const size_t id, connection &&conn)
|
||||
: id(id)
|
||||
, conn(std::move(conn)){}
|
||||
|
||||
|
|
@ -57,7 +57,9 @@ connection_pool::connection_pool(const std::string& dns, size_t count)
|
|||
: info_(connection_info::parse(dns)) {
|
||||
connection_repo_.reserve(count);
|
||||
while (count) {
|
||||
connection_repo_.emplace_back(count, connection{info_});
|
||||
connection c(info_);
|
||||
connection_repo_.emplace_back(count, std::move(c));
|
||||
// connection_repo_.emplace_back(count, connection{info_});
|
||||
auto &conn = connection_repo_.back();
|
||||
idle_connections_.emplace(conn.id, &conn);
|
||||
// Todo: handle result
|
||||
|
|
|
|||
|
|
@ -385,8 +385,7 @@ 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 = repo.attach<recipe>("recipes")
|
||||
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } )
|
||||
.and_then( [this] { return repo.attach<recipe_ingredient>("recipe_ingredients"); } );
|
||||
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } );
|
||||
|
||||
auto res = query::create()
|
||||
.table<recipe>("recipes", repo)
|
||||
|
|
@ -462,7 +461,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>(repo, true))
|
||||
.into("recipe_ingredients", column_generator::generate(repo, "recipe_ingredients", true))
|
||||
.values({ri.first, ri.second})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ struct flight {
|
|||
namespace field = matador::access;
|
||||
using namespace matador::utils;
|
||||
field::primary_key(op, "id", id);
|
||||
field::has_one(op, "airplane_id", plane, {utils::cascade_type::ALL, fetch_type::EAGER});
|
||||
field::belongs_to(op, "airplane_id", plane, {utils::cascade_type::ALL, fetch_type::EAGER});
|
||||
field::attribute(op, "pilot_name", pilot_name, 255);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue