progress on session::update

This commit is contained in:
Sascha Kühl 2025-10-10 15:51:51 +02:00
parent 463647ba59
commit 1fd2066946
2 changed files with 44 additions and 2 deletions

View File

@ -194,9 +194,10 @@ utils::result<object::object_ptr<Type>, utils::error> session::update( const obj
return utils::failure(info.err()); return utils::failure(info.err());
} }
const auto col = sql::column(info->get()->prototype().primary_key()->name());
auto res = query::query::update(info->get().name()) auto res = query::query::update(info->get().name())
.set(*obj) .set(*obj)
// .where(sql::column(info->prototype().primary_key()->name()) == _) .where(col == utils::_)
.prepare(*this); .prepare(*this);
if (!res) { if (!res) {
return utils::failure(res.err()); return utils::failure(res.err());

View File

@ -15,6 +15,48 @@ using namespace matador;
using namespace matador::object; using namespace matador::object;
using namespace matador::test; using namespace matador::test;
TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") {
const auto result = ses.attach<airplane>("airplanes")
.and_then([this] { return ses.create_schema(); } );
REQUIRE(result.is_ok());
tables_to_drop.emplace("airplanes");
auto plane = ses.insert<airplane>(1, "Boeing", "A380");
REQUIRE(plane.is_ok());
const auto res = ses.find<airplane>(1);
REQUIRE(res.is_ok());
const auto& read_airplane = *res;
REQUIRE(read_airplane->id == (*plane)->id);
REQUIRE(read_airplane->brand == (*plane)->brand);
REQUIRE(read_airplane->model == (*plane)->model);
}
TEST_CASE_METHOD(SessionFixture, "Session update test", "[session][update]") {
const auto res = ses.attach<airplane>("airplanes")
.and_then([this] { return ses.create_schema(); } );
REQUIRE(res.is_ok());
tables_to_drop.emplace("airplanes");
auto result = ses.insert<airplane>(1, "Boeing", "747");
REQUIRE(result.is_ok());
const auto plane = result.value();
result = ses.find<airplane>(1);
REQUIRE(result.is_ok());
const auto& read_airplane = *result;
REQUIRE(read_airplane->id == plane->id);
REQUIRE(read_airplane->brand == plane->brand);
REQUIRE(read_airplane->model == plane->model);
read_airplane->brand = "Airbus";
read_airplane->model = "A380";
auto update_result = ses.update(read_airplane);
}
TEST_CASE_METHOD(SessionFixture, "Session relation test", "[session][relation]") { TEST_CASE_METHOD(SessionFixture, "Session relation test", "[session][relation]") {
const auto result = ses.attach<airplane>("airplanes") const auto result = ses.attach<airplane>("airplanes")
.and_then([this] { return ses.attach<flight>("flights"); } ) .and_then([this] { return ses.attach<flight>("flights"); } )
@ -208,7 +250,6 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-many eager relation", "[session][find][many-to-many][eager]") { TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-many eager relation", "[session][find][many-to-many][eager]") {
auto result = ses.attach<recipe>("recipes") auto result = ses.attach<recipe>("recipes")
.and_then( [this] { return ses.attach<ingredient>("ingredients"); } ) .and_then( [this] { return ses.attach<ingredient>("ingredients"); } )
// .and_then( [this] { return ses.attach<recipe_ingredient>("recipe_ingredients"); } )
.and_then( [this] { return ses.create_schema(); } ); .and_then( [this] { return ses.create_schema(); } );
tables_to_drop.emplace("recipes"); tables_to_drop.emplace("recipes");