introduced make_object function to create object_ptr instances and removed some session::insert overloads for simplicity

This commit is contained in:
2026-02-16 11:29:27 +01:00
parent a2a6448e03
commit ae7c1f510f
3 changed files with 63 additions and 87 deletions
+4 -31
View File
@@ -107,12 +107,12 @@ public:
* @param obj Object to insert
* @return Inserted object
*/
template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> insert(Type *obj);
// template<typename Type>
// utils::result<object::object_ptr<Type>, utils::error> insert(Type *obj);
template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> insert(object::object_ptr<Type> obj);
template<class Type, typename... Args>
utils::result<object::object_ptr<Type>, utils::error> insert(Args &&... args);
// template<class Type, typename... Args>
// utils::result<object::object_ptr<Type>, utils::error> insert(Args &&... args);
template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> update(const object::object_ptr<Type> &obj);
@@ -157,28 +157,6 @@ private:
std::shared_ptr<sql::resolver_service> resolver_service_;
};
template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj) {
std::shared_ptr<Type> ptr(obj);
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(it->second.name(), query::generator::columns<Type>(schema_))
.values(query::generator::placeholders<Type>())
.prepare(*this);
if (!res) {
return utils::failure(res.err());
}
if (const auto insert_result = res->bind(*obj).execute(); !insert_result.is_ok()) {
return utils::failure(insert_result.err());
}
return utils::ok(object::object_ptr{ptr});
}
template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> session::insert(object::object_ptr<Type> obj) {
const auto it = schema_.find(typeid(Type));
@@ -200,11 +178,6 @@ utils::result<object::object_ptr<Type>, utils::error> session::insert(object::ob
return utils::ok(obj);
}
template<class Type, typename... Args>
utils::result<object::object_ptr<Type>, utils::error> session::insert(Args &&... args) {
return insert(new Type(std::forward<Args>(args)...));
}
class pk_object_binder final {
public:
explicit pk_object_binder(sql::statement &stmt, const size_t position)