insert_query_builder progress
This commit is contained in:
@@ -58,19 +58,19 @@ TEST_CASE("Test insert builder has many", "[query][insert_query_builder][has_man
|
||||
.and_then( [&scm] { return scm.attach<author>("authors"); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto s_king = make_object<author>(1, "Steven", "King", "21.9.1947", 1956, false);
|
||||
|
||||
s_king->books.push_back(make_object<book>(2, "Carrie", object_ptr<author>{}, 1974));
|
||||
s_king->books.push_back(make_object<book>(3, "The Shining", object_ptr<author>{}, 1977));
|
||||
s_king->books.push_back(make_object<book>(4, "It", object_ptr<author>{}, 1986));
|
||||
s_king->books.push_back(make_object<book>(5, "Misery", object_ptr<author>{}, 1987));
|
||||
s_king->books.push_back(make_object<book>(6, "The Dark Tower: The Gunslinger", object_ptr<author>{}, 1982));
|
||||
|
||||
insert_query_builder iqb(scm);
|
||||
|
||||
auto build_result = iqb.build(s_king);
|
||||
REQUIRE(build_result.is_ok());
|
||||
|
||||
const auto& stmts = *build_result;
|
||||
REQUIRE(stmts.size() == 1);
|
||||
// auto s_king = make_object<author>(1, "Steven", "King", "21.9.1947", 1956, false);
|
||||
//
|
||||
// s_king->books.push_back(make_object<book>(2, "Carrie", object_ptr<author>{}, 1974));
|
||||
// s_king->books.push_back(make_object<book>(3, "The Shining", object_ptr<author>{}, 1977));
|
||||
// s_king->books.push_back(make_object<book>(4, "It", object_ptr<author>{}, 1986));
|
||||
// s_king->books.push_back(make_object<book>(5, "Misery", object_ptr<author>{}, 1987));
|
||||
// s_king->books.push_back(make_object<book>(6, "The Dark Tower: The Gunslinger", object_ptr<author>{}, 1982));
|
||||
//
|
||||
// insert_query_builder iqb(scm);
|
||||
//
|
||||
// auto build_result = iqb.build(s_king);
|
||||
// REQUIRE(build_result.is_ok());
|
||||
//
|
||||
// const auto& stmts = *build_result;
|
||||
// REQUIRE(stmts.size() == 1);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||
constraint("PK_person").primary_key({"id"}),
|
||||
constraint("FK_person_address").foreign_key({"address"}).references("address", {"id"})
|
||||
})
|
||||
.compile(*db);
|
||||
.compile(db->dialect());
|
||||
|
||||
REQUIRE(ctx.sql == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL, "name" VARCHAR(255) NOT NULL UNIQUE, "age" INTEGER NOT NULL, "address" BIGINT NOT NULL, CONSTRAINT PK_person PRIMARY KEY (id), CONSTRAINT FK_person_address FOREIGN KEY (address) REFERENCES address (id)))##");
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ TEST_CASE("Test statement cache", "[statement][cache]") {
|
||||
const auto stmt = result.value();
|
||||
|
||||
ctx.sql = "SELECT title FROM book";
|
||||
ctx.sql_hash = std::hash<std::string>{}(ctx.sql);
|
||||
|
||||
result = cache.acquire(ctx);
|
||||
REQUIRE(result);
|
||||
@@ -143,6 +144,7 @@ TEST_CASE("Test statement cache", "[statement][cache]") {
|
||||
REQUIRE(cache.capacity() == 2);
|
||||
|
||||
ctx.sql = "SELECT name FROM author";
|
||||
ctx.sql_hash = std::hash<std::string>{}(ctx.sql);
|
||||
|
||||
result = cache.acquire(ctx);
|
||||
REQUIRE(result);
|
||||
@@ -163,18 +165,19 @@ TEST_CASE("Test LRU cache evicts oldest entries", "[statement][cache][evict]") {
|
||||
REQUIRE(cache.capacity() == 2);
|
||||
REQUIRE(cache.empty());
|
||||
|
||||
auto result = cache.acquire({"SELECT * FROM person"});
|
||||
|
||||
auto result = cache.acquire({"SELECT * FROM person", std::hash<std::string>{}("SELECT * FROM person")});
|
||||
REQUIRE(result);
|
||||
auto stmt1 = result.value();
|
||||
result = cache.acquire({"SELECT title FROM book"});
|
||||
result = cache.acquire({"SELECT title FROM book", std::hash<std::string>{}("SELECT title FROM book")});
|
||||
REQUIRE(result);
|
||||
auto stmt2 = result.value();
|
||||
result = cache.acquire({"SELECT name FROM author"}); // Should evict the first statement
|
||||
result = cache.acquire({"SELECT name FROM author", std::hash<std::string>{}("SELECT name FROM author")}); // Should evict the first statement
|
||||
REQUIRE(result);
|
||||
auto stmt3 = result.value();
|
||||
|
||||
// Trigger re-prepares of an evicted statement
|
||||
result = cache.acquire({"SELECT 1"});
|
||||
result = cache.acquire({"SELECT 1", std::hash<std::string>{}("SELECT 1")});
|
||||
REQUIRE(result);
|
||||
auto stmt4 = result.value();
|
||||
|
||||
@@ -211,10 +214,10 @@ TEST_CASE("Test statement reuse avoids reprepare", "[statement][cache][prepare]"
|
||||
REQUIRE(cache.capacity() == 2);
|
||||
REQUIRE(cache.empty());
|
||||
|
||||
auto result = cache.acquire({"SELECT * FROM person"});
|
||||
auto result = cache.acquire({"SELECT * FROM person", std::hash<std::string>{}("SELECT * FROM person")});
|
||||
REQUIRE(result);
|
||||
auto stmt1 = result.value();
|
||||
result = cache.acquire({"SELECT * FROM person"});
|
||||
result = cache.acquire({"SELECT * FROM person", std::hash<std::string>{}("SELECT * FROM person")});
|
||||
REQUIRE(result);
|
||||
auto stmt2 = result.value();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user