added where condition
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
Include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.4.0 # or a later release
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests builder.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain matador)
|
||||
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <matador/sql/column.hpp>
|
||||
#include <matador/sql/condition.hpp>
|
||||
#include <matador/sql/dialect.hpp>
|
||||
#include <matador/sql/query_builder.hpp>
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Create table", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.create().table("person", {
|
||||
make_pk_column<unsigned long>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<unsigned short>("age")
|
||||
}).compile();
|
||||
|
||||
REQUIRE(sql == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL PRIMARY KEY, "name" VARCHAR(255), "age" INTEGER))##");
|
||||
}
|
||||
|
||||
TEST_CASE("Drop table", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.drop().table("person").compile();
|
||||
|
||||
REQUIRE(sql == R"(DROP TABLE "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Select", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"}).from("person").compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Insert", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.insert().into("person", {
|
||||
"id", "name", "age"
|
||||
}).values({7UL, "george", 65U}).compile();
|
||||
|
||||
REQUIRE(sql == R"(INSERT INTO "person" ("id", "name", "age") VALUES (7, 'george', 65))");
|
||||
}
|
||||
|
||||
TEST_CASE("Update", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.update("person").set({
|
||||
{"id", 7UL},
|
||||
{"name", "george"},
|
||||
{"age", 65U}
|
||||
}).compile();
|
||||
|
||||
REQUIRE(sql == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
|
||||
}
|
||||
|
||||
TEST_CASE("Delete", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.remove().from("person").compile();
|
||||
|
||||
REQUIRE(sql == R"(DELETE FROM "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Where", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == 8)
|
||||
.compile();
|
||||
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
Reference in New Issue
Block a user