mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-05 00:49:58 -06:00
Added a caching strategy (#83)
This commit is contained in:
committed by
GitHub
parent
4cc3e871c3
commit
86ee6e2bcc
45
tests/sqlite/test_cache.cpp
Normal file
45
tests/sqlite/test_cache.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <sqlgen.hpp>
|
||||
#include <sqlgen/sqlite.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace test_cache {
|
||||
|
||||
struct User {
|
||||
std::string name;
|
||||
int age;
|
||||
};
|
||||
|
||||
TEST(sqlite, test_cache) {
|
||||
const auto conn = sqlgen::sqlite::connect();
|
||||
|
||||
const auto user = User{.name = "John", .age = 30};
|
||||
sqlgen::write(conn, user);
|
||||
|
||||
using namespace sqlgen;
|
||||
using namespace sqlgen::literals;
|
||||
|
||||
const auto query = sqlgen::read<User> | where("name"_c == "John");
|
||||
|
||||
const auto cached_query = sqlgen::cache<100>(query);
|
||||
|
||||
const auto user1 = conn.and_then(cache<100>(query)).value();
|
||||
|
||||
EXPECT_EQ(cached_query.cache(conn).size(), 1);
|
||||
|
||||
const auto user2 = cached_query(conn).value();
|
||||
const auto user3 = cached_query(conn).value();
|
||||
|
||||
EXPECT_EQ(user1.name, "John");
|
||||
EXPECT_EQ(user1.age, 30);
|
||||
EXPECT_EQ(user2.name, "John");
|
||||
EXPECT_EQ(user2.age, 30);
|
||||
EXPECT_EQ(cached_query.cache(conn).size(), 1);
|
||||
EXPECT_EQ(user3.name, "John");
|
||||
EXPECT_EQ(user3.age, 30);
|
||||
}
|
||||
|
||||
} // namespace test_cache
|
||||
Reference in New Issue
Block a user