Pull in full sqlite_modern_cpp repo for the license as it is not attached to source files

This commit is contained in:
Saood Karim
2025-08-17 08:25:37 -05:00
parent a3b174b69a
commit ed9504bd92
41 changed files with 2654 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#include<iostream>
#include<sqlite_modern_cpp.h>
#include<string>
#include<vector>
#include<catch2/catch.hpp>
using namespace sqlite;
using namespace std;
template<typename Target, typename... AttrTypes>
struct builder {
vector<Target> results;
void operator()(AttrTypes... args) {
results.emplace_back(std::forward<AttrTypes&&>(args)...);
};
};
struct user {
int age;
string name;
double weight;
user(int age, string name, double weight) : age(age), name(name), weight(weight) { }
static std::vector<user> all(sqlite::database& db) {
builder<user, int, std::string, double> person_builder;
db << "SELECT * FROM user;"
>> person_builder;
return std::move(person_builder.results); // move to avoid copying data ;-)
};
};
TEST_CASE("lvalue functors work", "[lvalue_functor]") {
database db(":memory:");
db <<
"create table if not exists user ("
" age int,"
" name text,"
" weight real"
");";
db << "insert into user (age,name,weight) values (?,?,?);" << 20 << u"chandler" << 83.25;
db << "insert into user (age,name,weight) values (?,?,?);" << 21 << u"monika" << 86.25;
db << "insert into user (age,name,weight) values (?,?,?);" << 22 << u"ross" << 88.25;
auto users = user::all(db);
REQUIRE(users.size() == 3);
}