proxy lazy resolve progress
This commit is contained in:
parent
6b24a0e413
commit
f1323accda
|
|
@ -58,7 +58,7 @@ using namespace work::models;
|
|||
// the database.
|
||||
// schema.attach<jobs::Payload>("payloads", make_polymorph("type"));
|
||||
// schema.attach<jobs::Payload, jobs::IdPayload>("id_list_payloads", make_polymorph_type("IdPayload"));
|
||||
// schema.attach<jobs::Payload, jobs::IdListPayload>("id_payloads"make_polymorph_type("IdListPayload"));
|
||||
// schema.attach<jobs::Payload, jobs::IdListPayload>("id_payloads", make_polymorph_type("IdListPayload"));
|
||||
// object::object_ptr<jobs::Payload> payload;
|
||||
// auto result = payload.as<jobs::IdPayload>();
|
||||
// if (result.is_ok()) {
|
||||
|
|
@ -73,14 +73,18 @@ int main() {
|
|||
// logger::default_min_log_level(logger::log_level::LVL_DEBUG);
|
||||
// logger::add_log_sink(logger::create_stdout_sink());
|
||||
|
||||
const object::schema schema("Administration");
|
||||
|
||||
// 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");
|
||||
|
||||
auto result = admin_schema.attach<admin::CollectionCenter>("collection_centers");
|
||||
admin_schema.create(pool);
|
||||
admin_schema.drop(pool);
|
||||
|
||||
orm::session ses(pool);
|
||||
|
||||
auto result = ses.attach<admin::CollectionCenter>("collection_centers")
|
||||
result = ses.attach<admin::CollectionCenter>("collection_centers")
|
||||
.and_then([&ses] { return ses.attach<admin::UserDirectory>("user_directories"); })
|
||||
.and_then([&ses] { return ses.attach<admin::LdapGroupSchemaSettings>("ldap_group_schema_settings"); })
|
||||
.and_then([&ses] { return ses.attach<admin::LdapImportSettings>("ldap_import_settings"); })
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef QUERY_BUILDER_EXCEPTION_HPP
|
||||
#define QUERY_BUILDER_EXCEPTION_HPP
|
||||
|
||||
#include "matador/utils/error.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <system_error>
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
|
|
@ -10,18 +11,20 @@ enum class query_build_error : std::uint8_t {
|
|||
Ok = 0,
|
||||
UnknownType,
|
||||
MissingPrimaryKey,
|
||||
UnexpectedError
|
||||
UnexpectedError,
|
||||
QueryError
|
||||
};
|
||||
|
||||
|
||||
class query_builder_exception final : public std::exception {
|
||||
public:
|
||||
explicit query_builder_exception(const query_build_error error) : error_(error) {}
|
||||
explicit query_builder_exception(const query_build_error error, utils::error &&err = {});
|
||||
|
||||
[[nodiscard]] query_build_error error() const { return error_; }
|
||||
[[nodiscard]] query_build_error error_type() const;
|
||||
[[nodiscard]] const utils::error &error() const;
|
||||
|
||||
private:
|
||||
const query_build_error error_;
|
||||
const query_build_error error_type_;
|
||||
utils::error error_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,10 +50,6 @@ public:
|
|||
|
||||
template<typename Type, typename PrimaryKeyType>
|
||||
utils::result<object::object_ptr<Type>, utils::error> find(const PrimaryKeyType &pk) {
|
||||
// auto c = pool_.acquire();
|
||||
// if (!c.valid()) {
|
||||
// return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));
|
||||
// }
|
||||
auto info = schema_->info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
|
|
@ -78,10 +74,6 @@ public:
|
|||
|
||||
template<typename Type>
|
||||
utils::result<sql::query_result<Type>, utils::error> find() {
|
||||
// const auto c = pool_.acquire();
|
||||
// if (!c.valid()) {
|
||||
// return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));
|
||||
// }
|
||||
auto info = schema_->info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
|
|
@ -93,7 +85,13 @@ public:
|
|||
return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + info->get().name() + "."));
|
||||
}
|
||||
|
||||
return build_select_query(data.release()).template fetch_all<Type>(*this);
|
||||
const auto ctx = build_select_query(data.release()).compile(dialect_, query::query_mode::Prepared);
|
||||
|
||||
auto result = fetch(ctx);
|
||||
if (!result.is_ok()) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
return utils::ok(sql::query_result<Type>(result.release(), []{ return new Type();}));
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
|
@ -139,7 +137,6 @@ utils::result<void, utils::error> session::attach( const std::string& table_name
|
|||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj) {
|
||||
// auto c = pool_.acquire();
|
||||
auto info = schema_->info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
#include "matador/sql/executor.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
|
||||
#include "matador/object/join_columns_collector.hpp"
|
||||
#include "matador/object/schema.hpp"
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
#include "matador/utils/value.hpp"
|
||||
|
||||
#include <stack>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ struct entity_query_data {
|
|||
std::shared_ptr<sql::table> root_table;
|
||||
std::string pk_column_name{};
|
||||
std::vector<sql::column> columns{};
|
||||
std::unordered_map<std::string, sql::statement> lazy_loading_statements{};
|
||||
std::vector<query::join_data> joins{};
|
||||
std::unique_ptr<query::basic_condition> where_clause{};
|
||||
};
|
||||
|
|
@ -50,7 +51,7 @@ public:
|
|||
|
||||
return {utils::ok(std::move(entity_query_data_))};
|
||||
} catch (const query_builder_exception &ex) {
|
||||
return {utils::failure(ex.error())};
|
||||
return {utils::failure(ex.error_type())};
|
||||
} catch (...) {
|
||||
return {utils::failure(query_build_error::UnexpectedError)};
|
||||
}
|
||||
|
|
@ -71,7 +72,7 @@ public:
|
|||
|
||||
return {utils::ok(std::move(entity_query_data_))};
|
||||
} catch (const query_builder_exception &ex) {
|
||||
return {utils::failure(ex.error())};
|
||||
return {utils::failure(ex.error_type())};
|
||||
} catch (...) {
|
||||
return {utils::failure(query_build_error::UnexpectedError)};
|
||||
}
|
||||
|
|
@ -286,10 +287,15 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
|
|||
using namespace matador::utils;
|
||||
using namespace matador::query;
|
||||
// create select query
|
||||
const auto result = matador::query::query::select<typename Pointer::value_type>(schema_)
|
||||
auto result = matador::query::query::select<typename Pointer::value_type>(schema_)
|
||||
.from(*foreign_table)
|
||||
.where(sql::column(foreign_table, id, "") == _)
|
||||
.prepare(executor_);
|
||||
if (!result) {
|
||||
throw query_builder_exception(query_build_error::QueryError, result.release_error());
|
||||
}
|
||||
|
||||
entity_query_data_.lazy_loading_statements.emplace(id, std::move(result.release()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,10 +129,15 @@ public:
|
|||
|
||||
public:
|
||||
explicit query_result(std::unique_ptr<query_result_impl> &&impl)
|
||||
: impl_(std::move(impl)) {}
|
||||
: impl_(std::move(impl))
|
||||
, creator_([this]{ return detail::create_prototype<Type>(impl_->prototype()); } ) {}
|
||||
|
||||
query_result(std::unique_ptr<query_result_impl> &&impl, creator_func&& creator)
|
||||
: impl_(std::move(impl))
|
||||
, creator_(std::move(creator)) {}
|
||||
|
||||
iterator begin() { return std::move(++iterator(this)); }
|
||||
iterator end() { return {}; }
|
||||
static iterator end() { return {}; }
|
||||
|
||||
private:
|
||||
friend class query_result_iterator<Type>;
|
||||
|
|
@ -143,12 +148,14 @@ private:
|
|||
|
||||
protected:
|
||||
std::unique_ptr<query_result_impl> impl_;
|
||||
creator_func creator_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
Type *query_result<Type>::create() {
|
||||
return detail::create_prototype<Type>(impl_->prototype());
|
||||
return creator_();
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void query_result<Type>::bind(const Type &obj) {
|
||||
impl_->bind(obj);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/sql/statement.hpp
|
||||
../../include/matador/sql/table.hpp
|
||||
orm/error_code.cpp
|
||||
orm/query_builder_exception.cpp
|
||||
orm/session.cpp
|
||||
orm/session_insert_builder.cpp
|
||||
orm/session_query_builder.cpp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
#include "matador/orm/query_builder_exception.hpp"
|
||||
|
||||
namespace matador::orm {
|
||||
|
||||
query_builder_exception::query_builder_exception( const query_build_error error, utils::error&& err )
|
||||
: error_type_(error)
|
||||
, error_( std::move(err) ) {}
|
||||
|
||||
query_build_error query_builder_exception::error_type() const {
|
||||
return error_type_;
|
||||
}
|
||||
|
||||
const utils::error& query_builder_exception::error() const {
|
||||
return error_;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue