added connection impl class
This commit is contained in:
+2
-1
@@ -9,6 +9,7 @@ FetchContent_Declare(
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests builder.cpp
|
||||
connection.cpp)
|
||||
connection.cpp
|
||||
record.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain matador)
|
||||
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
||||
+9
-9
@@ -9,7 +9,7 @@ using namespace matador::sql;
|
||||
TEST_CASE("Execute create table statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
c.create()
|
||||
const auto res = c.create()
|
||||
.table("person", {
|
||||
make_pk_column<unsigned long>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
@@ -17,17 +17,17 @@ TEST_CASE("Execute create table statement", "[connection]") {
|
||||
}).execute();
|
||||
|
||||
REQUIRE(true);
|
||||
// REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
REQUIRE(res.second == R"(CREATE TABLE "person" ("id" BIGINT NOT NULL PRIMARY KEY, "name" VARCHAR(255), "age" INTEGER))");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute drop table statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
c.drop()
|
||||
.table("person").execute();
|
||||
const auto res = c.drop()
|
||||
.table("person")
|
||||
.execute();
|
||||
|
||||
REQUIRE(true);
|
||||
// REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
REQUIRE(res.second == R"(DROP TABLE "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with where clause", "[connection]") {
|
||||
@@ -38,7 +38,7 @@ TEST_CASE("Execute select statement with where clause", "[connection]") {
|
||||
.where("id"_col == 8)
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
REQUIRE(res.str() == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with order by", "[connection]") {
|
||||
@@ -50,7 +50,7 @@ TEST_CASE("Execute select statement with order by", "[connection]") {
|
||||
.order_by("name").desc()
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 ORDER BY "name" DESC)");
|
||||
REQUIRE(res.str() == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 ORDER BY "name" DESC)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with group by and order by", "[connection]") {
|
||||
@@ -63,7 +63,7 @@ TEST_CASE("Execute select statement with group by and order by", "[connection]")
|
||||
.order_by("name").asc()
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 GROUP BY "color" ORDER BY "name" ASC)");
|
||||
REQUIRE(res.str() == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 GROUP BY "color" ORDER BY "name" ASC)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute insert statement", "[connection]") {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <matador/sql/record.hpp>
|
||||
|
||||
#include <list>
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Create record", "[record]") {
|
||||
record rec({
|
||||
make_pk_column<unsigned long>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<std::string>("color", 255)
|
||||
});
|
||||
|
||||
REQUIRE(rec.size() == 3);
|
||||
|
||||
std::list<std::string> expected_columns = {"id", "name", "color"};
|
||||
for(const auto &col : expected_columns) {
|
||||
REQUIRE(rec.find(col) != rec.end());
|
||||
}
|
||||
|
||||
for(const auto& col : rec) {
|
||||
expected_columns.remove(col.name());
|
||||
}
|
||||
|
||||
REQUIRE(expected_columns.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Append to record", "[record]") {
|
||||
record rec;
|
||||
|
||||
rec.append(make_pk_column<unsigned long>("id"));
|
||||
rec.append<std::string>("name", 255);
|
||||
rec.append<std::string>("color", 63);
|
||||
|
||||
REQUIRE(rec.size() == 3);
|
||||
|
||||
std::list<std::string> expected_columns = {"id", "name", "color"};
|
||||
for(const auto &col : expected_columns) {
|
||||
REQUIRE(rec.find(col) != rec.end());
|
||||
}
|
||||
|
||||
for(const auto& col : rec) {
|
||||
expected_columns.remove(col.name());
|
||||
}
|
||||
|
||||
REQUIRE(expected_columns.empty());
|
||||
}
|
||||
Reference in New Issue
Block a user