Compare commits

..

2 Commits

Author SHA1 Message Date
Sascha Kühl 7fd11ad174 added session to work.cpp 2025-07-08 14:15:45 +02:00
Sascha Kühl d4253ee4d0 removed redundant code in relation completer 2025-07-08 14:15:32 +02:00
4 changed files with 30 additions and 50 deletions

View File

@ -19,5 +19,7 @@ target_link_libraries(work PRIVATE
matador-core matador-core
matador-orm matador-orm
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
${SQLite3_LIBRARIES} ${PostgreSQL_LIBRARY}
) )
add_dependencies(work matador-postgres)

View File

@ -89,11 +89,16 @@ int main() {
.and_then([&schema] { return schema.attach<jobs::IdListPayload, jobs::Payload>("id_payloads"); }) .and_then([&schema] { return schema.attach<jobs::IdListPayload, jobs::Payload>("id_payloads"); })
.and_then([&schema] { return schema.attach<jobs::Task>("tasks"); }); .and_then([&schema] { return schema.attach<jobs::Task>("tasks"); });
if (!result.is_ok()) { if (!result) {
std::cout << "error: " << result.err().message() << std::endl; std::cout << "error: " << result.err().message() << std::endl;
return 0; return 0;
} }
sql::connection_pool<sql::connection> pool("postgres://test:test123!@127.0.0.1:15432/postgres", 4);
orm::session ses(pool);
result = ses.create_schema();
schema.dump(std::cout); schema.dump(std::cout);
// const std::string dns{"sqlite://demo.db"}; // const std::string dns{"sqlite://demo.db"};
// sql::connection c(dns); // sql::connection c(dns);

View File

@ -17,7 +17,7 @@
namespace matador { namespace matador {
/** /**
* Base class for several kind of socket * Base class for some kind of socket
* classes (acceptor, stream) representing a * classes (acceptor, stream) representing a
* socket. The protocol is selected via the * socket. The protocol is selected via the
* template parameter (/sa tcp and udp classes) * template parameter (/sa tcp and udp classes)
@ -72,7 +72,7 @@ public:
* Releases the socket fd and sets * Releases the socket fd and sets
* the internal socket to zero (0). * the internal socket to zero (0).
* *
* After the socket is released the user * After the socket is released, the user
* is in charge to take of the socket * is in charge to take of the socket
* *
* @return The released socket fd * @return The released socket fd
@ -81,8 +81,8 @@ public:
/** /**
* Connect to the given peer. If the connection * Connect to the given peer. If the connection
* could be established true is returned, * could be established, true is returned,
* otherwise false is returned and errno is set. * otherwise false is returned, and errno is set.
* *
* @param p Peer to execute to * @param p Peer to execute to
* @return True on successful connection * @return True on successful connection
@ -91,21 +91,21 @@ public:
/** /**
* Sets the socket either blocking (false) or * Sets the socket either blocking (false) or
* non blocking (true). * non-blocking (true).
* *
* @param nb True sets the socket non blocking false blocking * @param nb True sets the socket non blocking false blocking
*/ */
void non_blocking(bool nb); void non_blocking(bool nb);
/** /**
* Returns true if the socket is non blocking * Returns true if the socket is non-blocking
* otherwise returns false * otherwise returns false
* @return True if socket is non blocking * @return True if the socket is non-blocking
*/ */
bool non_blocking() const; bool non_blocking() const;
/** /**
* Set or unset the cose on exec flag * Set or unset the cose on the exec flag
* for the socket * for the socket
* *
* @param nb Flag to set or unset cloexec option * @param nb Flag to set or unset cloexec option
@ -113,15 +113,15 @@ public:
void cloexec(bool nb); void cloexec(bool nb);
/** /**
* Returns true if close on exec option is set * Returns true if the close-on-exec option is set
* *
* @return True on set cloexec option * @return True on set cloexec option
*/ */
bool cloexec() const; bool cloexec() const;
/** /**
* Sets a socket option represented by name. If option * Sets a socket option represented by name. If the option
* was successfully set true is returned. Otherwise false * was successfully set, true is returned. Otherwise, false
* and errno ist set. * and errno ist set.
* *
* @param name Option name * @param name Option name
@ -139,7 +139,7 @@ public:
/** /**
* Assigns the given socket fd to this * Assigns the given socket fd to this
* socket. If the socket is already opened * socket. If the socket is already opened,
* an exception is thrown. * an exception is thrown.
* *
* @param sock The socket fd to assign * @param sock The socket fd to assign

View File

@ -385,42 +385,15 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
template<typename Type> template<typename Type>
template<class CollectionType> template<class CollectionType>
void relation_completer<Type>::on_has_many_to_many(const char *id, void relation_completer<Type>::on_has_many_to_many(const char *id,
CollectionType &/*collection*/, CollectionType &collection,
const utils::foreign_attributes &/*attr*/) { const utils::foreign_attributes &attr) {
auto result = schema_.find_node(id); const auto join_columns = join_columns_collector_.collect<typename CollectionType::value_type::value_type>();
if (!result) { on_has_many_to_many(
const auto join_columns = join_columns_collector_.collect<typename CollectionType::value_type::value_type>(); id,
using relation_value_type = many_to_many_relation<typename CollectionType::value_type::value_type, Type>; collection,
auto creator = [&join_columns] { join_columns.inverse_join_column.c_str(),
return std::make_unique<relation_value_type>(join_columns.inverse_join_column, join_columns.join_column); join_columns.join_column.c_str(),
}; attr);
auto node = schema_node::make_relation_node<relation_value_type>(schema_, id, std::move(creator));
auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
auto join_endpoint = std::make_shared<relation_endpoint>(join_columns.join_column, relation_type::BELONGS_TO, node);
auto inverse_join_endpoint = std::make_shared<relation_endpoint>(join_columns.inverse_join_column,
relation_type::BELONGS_TO, node);
node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint);
node->info_->register_relation_endpoint(node_->type_index(), inverse_join_endpoint);
link_relation_endpoints(local_endpoint, inverse_join_endpoint);
node->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), join_endpoint);
result = schema_.attach_node(node, "");
if (!result) {
// Todo: throw internal error
return;
}
} else {
const auto &foreign_node = result.value();
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint);
const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index());
if (it == foreign_node->info().endpoint_end()) {
// Todo: Throw internal error
return;
}
link_relation_endpoints(local_endpoint, it->second);
}
} }
template<typename Type> template<typename Type>