added value class
This commit is contained in:
+2
-1
@@ -40,7 +40,8 @@ add_executable(tests
|
||||
models/author.hpp
|
||||
models/book.hpp
|
||||
FieldTest.cpp
|
||||
models/recipe.hpp)
|
||||
models/recipe.hpp
|
||||
ValueTest.cpp)
|
||||
|
||||
target_link_libraries(tests PRIVATE
|
||||
Catch2::Catch2WithMain
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("Generate columns from object", "[column generator]") {
|
||||
TEST_CASE("Generate column definitions from object", "[column][definition][generator]") {
|
||||
schema repo("main");
|
||||
|
||||
auto columns = column_definition_generator::generate<matador::test::product>(repo);
|
||||
|
||||
@@ -17,9 +17,9 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
scm.attach<author>("authors");
|
||||
scm.attach<book>("books");
|
||||
|
||||
entity_query_builder eqb(17, scm);
|
||||
entity_query_builder eqb(scm);
|
||||
|
||||
auto data = eqb.build<book>();
|
||||
auto data = eqb.build<book>(17);
|
||||
|
||||
REQUIRE(data.has_value());
|
||||
REQUIRE(data->root_table_name == "books");
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> expected_join_data {
|
||||
{ "books", "books.author_id = authors.id"}
|
||||
{ "books", R"("books"."author_id" = "authors"."id")"}
|
||||
};
|
||||
|
||||
query_context qc;
|
||||
@@ -54,7 +54,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == "books.id = 17");
|
||||
REQUIRE(cond == R"("books"."id" = 17)");
|
||||
|
||||
auto q = db.query(scm)
|
||||
.select(data->columns)
|
||||
@@ -77,9 +77,9 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
scm.attach<order_details>("order_details");
|
||||
scm.attach<order>("orders");
|
||||
|
||||
entity_query_builder eqb(17, scm);
|
||||
entity_query_builder eqb(scm);
|
||||
|
||||
auto data = eqb.build<order>();
|
||||
auto data = eqb.build<order>(17);
|
||||
|
||||
REQUIRE(data.has_value());
|
||||
REQUIRE(data->root_table_name == "orders");
|
||||
@@ -107,7 +107,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> expected_join_data {
|
||||
{ "orders", "orders.order_id = order_details.order_id"}
|
||||
{ "orders", R"("orders"."order_id" = "order_details"."order_id")"}
|
||||
};
|
||||
|
||||
query_context qc;
|
||||
@@ -120,7 +120,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == "orders.order_id = 17");
|
||||
REQUIRE(cond == R"("orders"."order_id" = 17)");
|
||||
}
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager many to many", "[query][entity][builder]") {
|
||||
@@ -131,9 +131,9 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
scm.attach<ingredient>("ingredients");
|
||||
scm.attach<recipe_ingredient>("recipe_ingredients");
|
||||
|
||||
entity_query_builder eqb(17, scm);
|
||||
entity_query_builder eqb(scm);
|
||||
|
||||
auto data = eqb.build<ingredient>();
|
||||
auto data = eqb.build<ingredient>(17);
|
||||
|
||||
REQUIRE(data.has_value());
|
||||
REQUIRE(data->root_table_name == "ingredients");
|
||||
@@ -150,8 +150,8 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> expected_join_data {
|
||||
{ "ingredients", "ingredients.id = recipe_ingredients.ingredient_id"},
|
||||
{ "recipes", "recipes.id = recipe_ingredients.recipe_id"}
|
||||
{ "ingredients", R"("ingredients"."id" = "recipe_ingredients"."ingredient_id")"},
|
||||
{ "recipes", R"("recipes"."id" = "recipe_ingredients"."recipe_id")"}
|
||||
};
|
||||
|
||||
query_context qc;
|
||||
@@ -164,5 +164,5 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == "ingredients.id = 17");
|
||||
REQUIRE(cond == R"("ingredients"."id" = 17)");
|
||||
}
|
||||
+2
-2
@@ -9,8 +9,8 @@ TEST_CASE("Field test", "[field]") {
|
||||
|
||||
REQUIRE(f.name() == "name");
|
||||
REQUIRE(f.index() == -1);
|
||||
REQUIRE(f.is_unknown());
|
||||
REQUIRE(!f.is_null());
|
||||
REQUIRE(!f.is_unknown());
|
||||
REQUIRE(f.is_null());
|
||||
REQUIRE(!f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
REQUIRE(!f.is_blob());
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/value.hpp"
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Test value class", "[value]") {
|
||||
value v;
|
||||
|
||||
REQUIRE(v.is_unknown());
|
||||
REQUIRE(v.type() == data_type_t::type_unknown);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = 7;
|
||||
|
||||
REQUIRE(v.is_integer());
|
||||
REQUIRE(v.type() == data_type_t::type_int);
|
||||
REQUIRE(v.size() == 0);
|
||||
REQUIRE(v.as<int>() == 7);
|
||||
REQUIRE(v.as<long>() == 7);
|
||||
|
||||
v = "test";
|
||||
|
||||
REQUIRE(v.is_varchar());
|
||||
REQUIRE(v.type() == data_type_t::type_char_pointer);
|
||||
REQUIRE(v.size() == 4);
|
||||
|
||||
v = std::string{"hello"};
|
||||
|
||||
REQUIRE(v.is_varchar());
|
||||
REQUIRE(v.type() == data_type_t::type_varchar);
|
||||
REQUIRE(v.size() == 5);
|
||||
|
||||
v = 4.5;
|
||||
|
||||
REQUIRE(v.is_floating_point());
|
||||
REQUIRE(v.type() == data_type_t::type_double);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = 6.7f;
|
||||
|
||||
REQUIRE(v.is_floating_point());
|
||||
REQUIRE(v.type() == data_type_t::type_float);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = std::string();
|
||||
|
||||
REQUIRE(v.is_string());
|
||||
REQUIRE(v.type() == data_type_t::type_text);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = true;
|
||||
|
||||
REQUIRE(v.is_bool());
|
||||
REQUIRE(v.type() == data_type_t::type_bool);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = nullptr;
|
||||
|
||||
REQUIRE(v.is_null());
|
||||
REQUIRE(v.type() == data_type_t::type_null);
|
||||
REQUIRE(v.size() == 0);
|
||||
|
||||
v = matador::utils::blob{ 1, 2, 3, 4 };
|
||||
|
||||
REQUIRE(v.is_blob());
|
||||
REQUIRE(v.type() == data_type_t::type_blob);
|
||||
REQUIRE(v.size() == 4);
|
||||
}
|
||||
Reference in New Issue
Block a user