added update_object_binder progress

This commit is contained in:
Sascha Kühl 2025-10-14 15:05:25 +02:00
parent d0e2e4340e
commit d3483ea5c2
1 changed files with 17 additions and 1 deletions

View File

@ -188,6 +188,20 @@ utils::result<object::object_ptr<Type>, utils::error> session::insert( Args&&...
return insert(new Type(std::forward<Args>(args)...)); return insert(new Type(std::forward<Args>(args)...));
} }
class update_object_binder final {
public:
explicit update_object_binder(sql::statement &stmt)
: stmt_(stmt) {}
template < class Type >
sql::statement& bind(Type &obj) {
return stmt_;
}
private:
sql::statement &stmt_;
sql::object_pk_binder pk_binder_;
};
template<typename Type> template<typename Type>
utils::result<object::object_ptr<Type>, utils::error> session::update( const object::object_ptr<Type>& obj ) { utils::result<object::object_ptr<Type>, utils::error> session::update( const object::object_ptr<Type>& obj ) {
auto info = schema_->info<Type>(); auto info = schema_->info<Type>();
@ -206,7 +220,9 @@ utils::result<object::object_ptr<Type>, utils::error> session::update( const obj
return utils::failure(res.err()); return utils::failure(res.err());
} }
if (const auto update_result = res->bind(*obj).execute(); !update_result.is_ok()) { res->bind(*obj);
update_object_binder binder(res.value());;
if (const auto update_result = binder.bind(*obj).execute(); !update_result.is_ok()) {
return utils::failure(update_result.err()); return utils::failure(update_result.err());
} }
return utils::ok(object::object_ptr{obj}); return utils::ok(object::object_ptr{obj});