mirror of
https://github.com/getml/sqlgen.git
synced 2026-05-03 21:49:39 -05:00
Added aggregations and GROUP BY (#17)
This commit is contained in:
committed by
GitHub
parent
21564cacf6
commit
775f15babf
@@ -0,0 +1,50 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <ranges>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <sqlgen.hpp>
|
||||
#include <sqlgen/sqlite.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace test_range_select_from_with_to {
|
||||
|
||||
struct Person {
|
||||
sqlgen::PrimaryKey<uint32_t> id;
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
int age;
|
||||
};
|
||||
|
||||
TEST(sqlite, test_range_select_from_with_to) {
|
||||
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}});
|
||||
|
||||
using namespace sqlgen;
|
||||
|
||||
struct FirstName {
|
||||
std::string first_name;
|
||||
};
|
||||
|
||||
const auto people2 =
|
||||
sqlite::connect()
|
||||
.and_then(drop<Person> | if_exists)
|
||||
.and_then(write(std::ref(people1)))
|
||||
.and_then(select_from<Person>("first_name"_c) | order_by("id"_c) |
|
||||
to<std::vector<FirstName>>)
|
||||
.value();
|
||||
|
||||
EXPECT_EQ(people2.at(0).first_name, "Homer");
|
||||
EXPECT_EQ(people2.at(1).first_name, "Bart");
|
||||
EXPECT_EQ(people2.at(2).first_name, "Lisa");
|
||||
EXPECT_EQ(people2.at(3).first_name, "Maggie");
|
||||
}
|
||||
|
||||
} // namespace test_range_select_from_with_to
|
||||
|
||||
Reference in New Issue
Block a user