mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-03-11 22:40:01 +00:00
Pull in full sqlite_modern_cpp repo for the license as it is not attached to source files
This commit is contained in:
52
common/sqlite_modern_cpp/tests/lvalue_functor.cc
Normal file
52
common/sqlite_modern_cpp/tests/lvalue_functor.cc
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user