fixed postgres tests
This commit is contained in:
@@ -26,7 +26,7 @@ public:
|
||||
explicit session(sql::connection_pool<sql::connection> &pool);
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name);
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name) const;
|
||||
|
||||
utils::result<void, utils::error> create_schema() const;
|
||||
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
auto obj = build_select_query(data.release()).template fetch_one<Type>(*c);
|
||||
|
||||
if (!obj) {
|
||||
return utils::failure(obj.err());
|
||||
}
|
||||
if (!obj->get()) {
|
||||
return utils::failure(make_error(error_code::FailedToFindObject, "Failed to find object of type " + info->get().name() + " with primary key " + std::to_string(pk) + "."));
|
||||
}
|
||||
return utils::ok(object::object_ptr<Type>{ obj.release() });
|
||||
@@ -104,8 +107,8 @@ public:
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void drop_table();
|
||||
void drop_table(const std::string &table_name) const;
|
||||
utils::result<void, utils::error> drop_table();
|
||||
utils::result<void, utils::error> drop_table(const std::string &table_name) const;
|
||||
|
||||
[[nodiscard]] utils::result<sql::query_result<sql::record>, utils::error> fetch(const sql::query_context &q) const;
|
||||
// [[nodiscard]] query_result<record> fetch(const std::string &sql) const;
|
||||
@@ -133,8 +136,7 @@ private:
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> session::attach(const std::string &table_name)
|
||||
{
|
||||
[[nodiscard]] utils::result<void, utils::error> session::attach(const std::string &table_name) const {
|
||||
return schema_->attach<Type>(table_name);
|
||||
}
|
||||
|
||||
@@ -159,13 +161,14 @@ utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj)
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void session::drop_table()
|
||||
{
|
||||
utils::result<void, utils::error> session::drop_table() {
|
||||
auto info = schema_->info<Type>();
|
||||
if (info) {
|
||||
return drop_table(info.name);
|
||||
return drop_table(info->get().name());
|
||||
}
|
||||
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
|
||||
}
|
||||
#endif //QUERY_SESSION_HPP
|
||||
|
||||
@@ -62,10 +62,10 @@ private:
|
||||
|
||||
struct entity_query_data {
|
||||
std::string root_table_name;
|
||||
std::string pk_column_;
|
||||
std::vector<sql::column> columns;
|
||||
std::vector<query::join_data> joins;
|
||||
std::unique_ptr<query::basic_condition> where_clause;
|
||||
std::string pk_column_{};
|
||||
std::vector<sql::column> columns{};
|
||||
std::vector<query::join_data> joins{};
|
||||
std::unique_ptr<query::basic_condition> where_clause{};
|
||||
};
|
||||
|
||||
enum class query_build_error : std::uint8_t {
|
||||
@@ -175,7 +175,7 @@ public:
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * id, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
|
||||
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
|
||||
if (attr.fetch() == utils::fetch_type::EAGER) {
|
||||
const auto info = schema_.info<typename ContainerType::value_type::value_type>();
|
||||
if (!info) {
|
||||
|
||||
Reference in New Issue
Block a user