added returning token for insert query

This commit is contained in:
2026-02-15 18:34:12 +01:00
parent 9065355ee0
commit f38be4c6d9
16 changed files with 178 additions and 58 deletions
+24
View File
@@ -87,6 +87,30 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
}
}
TEST_CASE_METHOD(QueryFixture, "Execute insert with returning", "[query][insert][returning]") {
REQUIRE(repo.attach<person>("persons"));
auto result = repo.create(db);
REQUIRE(result.is_ok());
check_table_exists(PERSON.table_name());
person george{7, "george", 45};
george.image.emplace_back(37);
auto res = query::insert()
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
.values(george)
.returning(PERSON.id)
.fetch_one(db);
REQUIRE(res.is_ok());
auto rec = res.release();
REQUIRE(rec->size() == 1);
REQUIRE(rec->at(0).name() == "persons.id");
REQUIRE(rec->at(0).is_integer());
REQUIRE(rec->at(0).as<uint32_t>() == 7);
}
TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
auto res = query::create()
.table("person")