mirror of
https://github.com/getml/sqlgen.git
synced 2025-12-31 14:39:31 -06:00
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <rfl.hpp>
|
|
#include <rfl/json.hpp>
|
|
#include <sqlgen.hpp>
|
|
#include <sqlgen/sqlite.hpp>
|
|
#include <vector>
|
|
|
|
namespace test_single_read {
|
|
|
|
struct Person {
|
|
sqlgen::PrimaryKey<uint32_t> id;
|
|
std::string first_name;
|
|
std::string last_name;
|
|
int age;
|
|
};
|
|
|
|
TEST(sqlite, test_single_read) {
|
|
const auto people1 = std::vector<Person>(
|
|
{Person{
|
|
.id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45},
|
|
Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10},
|
|
Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8},
|
|
Person{
|
|
.id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}});
|
|
|
|
const auto conn = sqlgen::sqlite::connect();
|
|
|
|
sqlgen::write(conn, people1);
|
|
|
|
using namespace sqlgen;
|
|
|
|
const auto people2 =
|
|
(sqlgen::read<Person> | where("id"_c == 0))(conn).value();
|
|
|
|
const auto json1 = rfl::json::write(people1.at(0));
|
|
const auto json2 = rfl::json::write(people2);
|
|
|
|
EXPECT_EQ(json1, json2);
|
|
}
|
|
|
|
} // namespace test_single_read
|