Better implementation for value_t; fixes #64 (#65)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-10-14 23:11:08 +02:00
committed by GitHub
parent 9c67ff24e4
commit 3736fcc29c
4 changed files with 87 additions and 41 deletions

View File

@@ -24,32 +24,42 @@ TEST(sqlite, test_insert_or_replace) {
Person{
.id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}});
const auto people2 = std::vector<Person>(
{Person{.id = 1, .first_name = "Bartholomew", .last_name = "Simpson", .age = 10},
Person{
.id = 3, .first_name = "Margaret", .last_name = "Simpson", .age = 1}});
const auto people2 = std::vector<Person>({Person{.id = 1,
.first_name = "Bartholomew",
.last_name = "Simpson",
.age = 10},
Person{.id = 3,
.first_name = "Margaret",
.last_name = "Simpson",
.age = 1}});
const auto people3 = std::vector<Person>(
{Person{
.id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45},
Person{.id = 1, .first_name = "Bartholomew", .last_name = "Simpson", .age = 10},
Person{.id = 1,
.first_name = "Bartholomew",
.last_name = "Simpson",
.age = 10},
Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8},
Person{
.id = 3, .first_name = "Margaret", .last_name = "Simpson", .age = 1}});
Person{.id = 3,
.first_name = "Margaret",
.last_name = "Simpson",
.age = 1}});
using namespace sqlgen;
using namespace sqlgen::literals;
const auto people4 = sqlite::connect()
.and_then(begin_transaction)
.and_then(create_table<Person> | if_not_exists)
.and_then(insert(people1))
.and_then(commit)
.and_then(begin_transaction)
.and_then(insert_or_replace(people2))
.and_then(commit)
.and_then(sqlgen::read<std::vector<Person>> | order_by("id"_c))
.value();
const auto people4 =
sqlite::connect()
.and_then(begin_transaction)
.and_then(create_table<Person> | if_not_exists)
.and_then(insert(people1))
.and_then(commit)
.and_then(begin_transaction)
.and_then(insert_or_replace(std::ref(people2)))
.and_then(commit)
.and_then(sqlgen::read<std::vector<Person>> | order_by("id"_c))
.value();
const auto json3 = rfl::json::write(people3);
const auto json4 = rfl::json::write(people4);