added date_type_t, time_type_t and timestamp, ensure allocated postgres resources are released, split repository into basic_repository and repository.
This commit is contained in:
@@ -109,7 +109,7 @@ public:
|
||||
utils::result<sql::query_result<Type>, utils::error> find(query::criteria_ptr clause = {});
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> drop_table();
|
||||
utils::result<void, utils::error> drop_table() const;
|
||||
utils::result<void, utils::error> drop_table(const std::string &table_name) const;
|
||||
|
||||
[[nodiscard]] utils::result<sql::query_result<sql::record>, utils::error> fetch_all(const sql::query_context &q) const;
|
||||
@@ -141,13 +141,13 @@ private:
|
||||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj) {
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
|
||||
auto res = query::query::insert()
|
||||
.into(info->get().name(), query::generator::columns<Type>(schema_))
|
||||
.into(it->second.name(), query::generator::columns<Type>(schema_))
|
||||
.values(query::generator::placeholders<Type>())
|
||||
.prepare(*this);
|
||||
if (!res) {
|
||||
@@ -214,15 +214,15 @@ private:
|
||||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::update( const object::object_ptr<Type>& obj ) {
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
using namespace matador::utils;
|
||||
using namespace matador::query;
|
||||
|
||||
const auto col = table_column(info.value().get().primary_key_attribute()->name());
|
||||
auto res = matador::query::query::update(info->get().name())
|
||||
const auto col = table_column(it->second.node().info().primary_key_attribute()->name());
|
||||
auto res = matador::query::query::update(it->second.name())
|
||||
.set(generator::column_value_pairs<Type>())
|
||||
.where(col == _)
|
||||
.prepare(*this);
|
||||
@@ -240,16 +240,16 @@ utils::result<object::object_ptr<Type>, utils::error> session::update( const obj
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> session::remove( const object::object_ptr<Type>& obj ) {
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
using namespace matador::utils;
|
||||
using namespace matador::query;
|
||||
|
||||
const auto col = table_column(info.value().get().primary_key_attribute()->name());
|
||||
const auto col = table_column(it->second.node().info().primary_key_attribute()->name());
|
||||
auto res = matador::query::query::remove()
|
||||
.from( info->get().name() )
|
||||
.from( it->second.name() )
|
||||
.where(col == _)
|
||||
.prepare(*this);
|
||||
if (!res) {
|
||||
@@ -299,15 +299,15 @@ utils::result<object::object_ptr<Type>, utils::error> session::find(const Primar
|
||||
|
||||
template<typename Type>
|
||||
utils::result<sql::query_result<Type>, utils::error> session::find(query::criteria_ptr clause) {
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
|
||||
session_query_builder eqb(schema_, *this);
|
||||
auto data = eqb.build<Type>(std::move(clause));
|
||||
if (!data.is_ok()) {
|
||||
return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + info->get().name() + "."));
|
||||
return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + it->second.name() + "."));
|
||||
}
|
||||
|
||||
auto result = build_select_query(data.release()).prepare(*this);
|
||||
@@ -319,13 +319,12 @@ utils::result<sql::query_result<Type>, utils::error> session::find(query::criter
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> session::drop_table() {
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (info) {
|
||||
return drop_table(info->get().name());
|
||||
utils::result<void, utils::error> session::drop_table() const {
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
|
||||
return utils::failure(info.err());
|
||||
return drop_table(it->second.name());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -278,8 +278,6 @@ private:
|
||||
struct table_info {
|
||||
const object::basic_object_info &info;
|
||||
query::table table;
|
||||
// std::reference_wrapper<const object::basic_object_info> info;
|
||||
// std::shared_ptr<query::table> table;
|
||||
};
|
||||
|
||||
std::stack<table_info> table_info_stack_{};
|
||||
@@ -325,7 +323,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
|
||||
using namespace matador::utils;
|
||||
using namespace matador::query;
|
||||
// create select query
|
||||
auto result = matador::query::query::select(generator::columns<typename Pointer::value_type>(schema_, generator::column_generator_options::ForceLazy))
|
||||
auto result = matador::query::query::select(generator::columns<typename Pointer::value_type>(schema_, foreign_table, generator::column_generator_options::ForceLazy))
|
||||
.from(foreign_table)
|
||||
.where(table_column(&foreign_table, info.primary_key_attribute()->name(), "") == _)
|
||||
.prepare(executor_);
|
||||
|
||||
Reference in New Issue
Block a user