some column interface refactorings
This commit is contained in:
@@ -111,12 +111,13 @@ TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][da
|
||||
|
||||
TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][identifier]" ) {
|
||||
using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
auto res = query::create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute("from", matador::utils::basic_type::type_varchar, 255),
|
||||
attribute("to", matador::utils::basic_type::type_varchar, 255)
|
||||
attribute("from", basic_type::type_varchar, 255),
|
||||
attribute("to", basic_type::type_varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -125,7 +126,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||
|
||||
// check table description
|
||||
std::vector<std::string> column_names = { "from", "to"};
|
||||
std::vector<matador::utils::basic_type> types = {matador::utils::basic_type::type_varchar, matador::utils::basic_type::type_varchar};
|
||||
std::vector types = {basic_type::type_varchar, basic_type::type_varchar};
|
||||
const auto columns = db.describe("quotes");
|
||||
REQUIRE(columns.is_ok());
|
||||
|
||||
@@ -171,9 +172,10 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||
|
||||
TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][column]" ) {
|
||||
using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
const auto start_quote = db.dialect().token_at(matador::sql::dialect_token::StartQuote);
|
||||
const auto end_quote = db.dialect().token_at(matador::sql::dialect_token::EndQuote);
|
||||
const auto start_quote = db.dialect().token_at(dialect_token::StartQuote);
|
||||
const auto end_quote = db.dialect().token_at(dialect_token::EndQuote);
|
||||
|
||||
const std::string column_name = "name_with_" + start_quote + "open_close_quotes" + end_quote + "_in_backend_ctx";
|
||||
|
||||
@@ -190,7 +192,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
auto res = query::create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute(name, matador::utils::basic_type::type_varchar, 255)
|
||||
attribute(name, basic_type::type_varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -201,7 +203,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
|
||||
for (const auto &col : *columns) {
|
||||
REQUIRE(col.name() == name);
|
||||
REQUIRE(col.type() == matador::utils::basic_type::type_varchar);
|
||||
REQUIRE(col.type() == basic_type::type_varchar);
|
||||
}
|
||||
|
||||
res = query::drop()
|
||||
@@ -214,11 +216,12 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals]") {
|
||||
using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
auto res = query::create()
|
||||
.table("escapes")
|
||||
.columns({
|
||||
attribute("name", matador::utils::basic_type::type_varchar, 255)
|
||||
attribute("name", basic_type::type_varchar, 255)
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
@@ -125,7 +125,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::insert()
|
||||
.into("person", {{"", "id", ""}, {"", "name", ""}, {"", "color", ""}})
|
||||
.into("person", {{"id", ""}, {"name", ""}, {"color", ""}})
|
||||
.values({7, "george", "green"})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
@@ -46,12 +46,14 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
|
||||
REQUIRE(data.is_ok());
|
||||
REQUIRE(data->root_table->name() == "flights");
|
||||
REQUIRE(data->joins.size() == 1);
|
||||
const auto flights = std::make_shared<table>("flights");
|
||||
const auto airplanes = std::make_shared<table>("airplanes");
|
||||
const std::vector<column> expected_columns {
|
||||
{ "flights", "id", "c01" },
|
||||
{ "airplanes", "id", "c02" },
|
||||
{ "airplanes", "brand", "c03" },
|
||||
{ "airplanes", "model", "c04" },
|
||||
{ "flights", "pilot_name", "c05" },
|
||||
{ flights, "id", "c01" },
|
||||
{ airplanes, "id", "c02" },
|
||||
{ airplanes, "brand", "c03" },
|
||||
{ airplanes, "model", "c04" },
|
||||
{ flights, "pilot_name", "c05" },
|
||||
};
|
||||
REQUIRE(data->columns.size() == expected_columns.size());
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
@@ -92,16 +94,18 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
REQUIRE(data.is_ok());
|
||||
REQUIRE(data->root_table->name() == "books");
|
||||
REQUIRE(data->joins.size() == 1);
|
||||
const auto books = std::make_shared<table>("books");
|
||||
const auto authors = std::make_shared<table>("authors");
|
||||
const std::vector<column> expected_columns {
|
||||
{ "books", "id", "c01" },
|
||||
{ "books", "title", "c02" },
|
||||
{ "authors", "id", "c03" },
|
||||
{ "authors", "first_name", "c04" },
|
||||
{ "authors", "last_name", "c05" },
|
||||
{ "authors", "date_of_birth", "c06" },
|
||||
{ "authors", "year_of_birth", "c07" },
|
||||
{ "authors", "distinguished", "c08" },
|
||||
{ "books", "published_in", "c09" }
|
||||
{ books, "id", "c01" },
|
||||
{ books, "title", "c02" },
|
||||
{ authors, "id", "c03" },
|
||||
{ authors, "first_name", "c04" },
|
||||
{ authors, "last_name", "c05" },
|
||||
{ authors, "date_of_birth", "c06" },
|
||||
{ authors, "year_of_birth", "c07" },
|
||||
{ authors, "distinguished", "c08" },
|
||||
{ books, "published_in", "c09" }
|
||||
};
|
||||
REQUIRE(data->columns.size() == expected_columns.size());
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
@@ -156,22 +160,24 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
REQUIRE(data.is_ok());
|
||||
REQUIRE(data->root_table->name() == "orders");
|
||||
REQUIRE(data->joins.size() == 1);
|
||||
const auto orders = std::make_shared<table>("orders");
|
||||
const auto order_details = std::make_shared<table>("order_details");
|
||||
const std::vector<column> expected_columns = {
|
||||
{ "orders", "order_id", "c01" },
|
||||
{ "orders", "order_date", "c02" },
|
||||
{ "orders", "required_date", "c03" },
|
||||
{ "orders", "shipped_date", "c04" },
|
||||
{ "orders", "ship_via", "c05" },
|
||||
{ "orders", "freight", "c06" },
|
||||
{ "orders", "ship_name", "c07" },
|
||||
{ "orders", "ship_address", "c08" },
|
||||
{ "orders", "ship_city", "c09" },
|
||||
{ "orders", "ship_region", "c10" },
|
||||
{ "orders", "ship_postal_code", "c11" },
|
||||
{ "orders", "ship_country", "c12" },
|
||||
{ "order_details", "order_details_id", "c13" },
|
||||
{ "order_details", "order_id", "c14" },
|
||||
{ "order_details", "product_id", "c15" }
|
||||
{ orders, "order_id", "c01" },
|
||||
{ orders, "order_date", "c02" },
|
||||
{ orders, "required_date", "c03" },
|
||||
{ orders, "shipped_date", "c04" },
|
||||
{ orders, "ship_via", "c05" },
|
||||
{ orders, "freight", "c06" },
|
||||
{ orders, "ship_name", "c07" },
|
||||
{ orders, "ship_address", "c08" },
|
||||
{ orders, "ship_city", "c09" },
|
||||
{ orders, "ship_region", "c10" },
|
||||
{ orders, "ship_postal_code", "c11" },
|
||||
{ orders, "ship_country", "c12" },
|
||||
{ order_details, "order_details_id", "c13" },
|
||||
{ order_details, "order_id", "c14" },
|
||||
{ order_details, "product_id", "c15" }
|
||||
};
|
||||
REQUIRE(data->columns.size() == expected_columns.size());
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
@@ -212,11 +218,13 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
REQUIRE(data.is_ok());
|
||||
REQUIRE(data->root_table->name() == "ingredients");
|
||||
REQUIRE(data->joins.size() == 2);
|
||||
const auto ingredients = std::make_shared<table>("ingredients");
|
||||
const auto recipes = std::make_shared<table>("recipes");
|
||||
const std::vector<column> expected_columns {
|
||||
{ "ingredients", "id", "c01" },
|
||||
{ "ingredients", "name", "c02" },
|
||||
{ "recipes", "id", "c03" },
|
||||
{ "recipes", "name", "c04" }
|
||||
{ ingredients, "id", "c01" },
|
||||
{ ingredients, "name", "c02" },
|
||||
{ recipes, "id", "c03" },
|
||||
{ recipes, "name", "c04" }
|
||||
};
|
||||
REQUIRE(data->columns.size() == expected_columns.size());
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
@@ -258,11 +266,13 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
|
||||
REQUIRE(data.is_ok());
|
||||
REQUIRE(data->root_table->name() == "courses");
|
||||
REQUIRE(data->joins.size() == 2);
|
||||
const auto courses = std::make_shared<table>("courses");
|
||||
const auto students = std::make_shared<table>("students");
|
||||
const std::vector<column> expected_columns {
|
||||
{ "courses", "id", "c01" },
|
||||
{ "courses", "title", "c02" },
|
||||
{ "students", "id", "c03" },
|
||||
{ "students", "name", "c04" }
|
||||
{ courses, "id", "c01" },
|
||||
{ courses, "title", "c02" },
|
||||
{ students, "id", "c03" },
|
||||
{ students, "name", "c04" }
|
||||
};
|
||||
REQUIRE(data->columns.size() == expected_columns.size());
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
|
||||
@@ -23,7 +23,7 @@ protected:
|
||||
TEST_CASE_METHOD(CriteriaFixture, "Test binary criteria", "[criteria][binary]") {
|
||||
const auto name_col = "name"_col;
|
||||
|
||||
REQUIRE(name_col.column_name() == "name");
|
||||
REQUIRE(name_col.name() == "name");
|
||||
|
||||
auto clause = name_col != "george";
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST_CASE("Generate columns from object", "[column][generator]") {
|
||||
REQUIRE(columns.size() == expected_columns.size());
|
||||
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
REQUIRE(expected_columns[i] == columns[i].column_name());
|
||||
REQUIRE(expected_columns[i] == columns[i].name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user