startet with connection query intermediates
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@ FetchContent_Declare(
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests builder.cpp)
|
||||
add_executable(tests builder.cpp
|
||||
connection.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain matador)
|
||||
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
||||
+43
-2
@@ -66,12 +66,53 @@ TEST_CASE("Delete", "[query]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Where", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
auto sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == 8 && "age"_col > 50)
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = 8 AND "age" > 50))");
|
||||
|
||||
sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == _ && "age"_col > 50)
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = ? AND "age" > 50))");
|
||||
}
|
||||
|
||||
TEST_CASE("OrderBy", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.order_by("name").asc()
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" ORDER BY "name" ASC)");
|
||||
}
|
||||
|
||||
TEST_CASE("GroupBy", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.group_by("age")
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" GROUP BY "age")");
|
||||
}
|
||||
|
||||
TEST_CASE("Limit", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == 8)
|
||||
.offset(10)
|
||||
.limit(20)
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" WHERE "id" = 8)");
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" OFFSET 10 LIMIT 20)");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <matador/sql/column.hpp>
|
||||
#include <matador/sql/condition.hpp>
|
||||
#include <matador/sql/connection.hpp>
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("CSelect", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.select({"id", "name", "color"})
|
||||
.from("person")
|
||||
.where("id"_col == 8)
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
Reference in New Issue
Block a user