some column interface refactorings
This commit is contained in:
parent
3b0b9615ca
commit
263c202c69
|
|
@ -302,7 +302,7 @@ utils::result<object::object_ptr<Type>, utils::error> session::find(const Primar
|
|||
const auto& type_info = info.value().get();
|
||||
|
||||
session_query_builder eqb(*schema_, *this);
|
||||
const query::column col(query::table{type_info.name()}, type_info.primary_key_attribute()->name());
|
||||
const query::column col(std::make_shared<query::table>(type_info.name()), type_info.primary_key_attribute()->name());
|
||||
using namespace matador::query;
|
||||
auto data = eqb.build<Type>(col == utils::_);
|
||||
if (!data.is_ok()) {
|
||||
|
|
|
|||
|
|
@ -10,25 +10,25 @@ namespace matador::query {
|
|||
|
||||
class table;
|
||||
|
||||
// ReSharper disable CppNonExplicitConvertingConstructor
|
||||
class column {
|
||||
public:
|
||||
column(const char *name, const std::string& as = ""); // NOLINT(*-explicit-constructor)
|
||||
column(std::string name, std::string as = "");
|
||||
column(sql::sql_function_t func, std::string name); // NOLINT(*-explicit-constructor)
|
||||
column(const class table &tab, std::string name, std::string as = "");
|
||||
column(std::string name, std::string as = ""); // NOLINT(*-explicit-constructor)
|
||||
column(sql::sql_function_t func, std::string name);
|
||||
// column(const class table &tab, std::string name, std::string as = "");
|
||||
column(const std::shared_ptr<table> &t, std::string name, std::string as = "");
|
||||
|
||||
[[nodiscard]] bool equals(const column &x) const;
|
||||
|
||||
column& as(std::string a);
|
||||
|
||||
[[nodiscard]] const std::string& column_name() const;
|
||||
[[nodiscard]] std::string full_name() const;
|
||||
[[nodiscard]] const std::string& alias_name() const;
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const std::string& alias() const;
|
||||
|
||||
[[nodiscard]] bool is_function() const;
|
||||
[[nodiscard]] sql::sql_function_t function() const;
|
||||
[[nodiscard]] bool has_alias() const;
|
||||
[[nodiscard]] std::string alias() const;
|
||||
|
||||
[[nodiscard]] std::shared_ptr<class table> table() const;
|
||||
void table(const std::shared_ptr<query::table>& t);
|
||||
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<query::table> table_;
|
||||
std::string name;
|
||||
std::string name_;
|
||||
std::string alias_;
|
||||
|
||||
sql::sql_function_t function_{sql::sql_function_t::None};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef MATADOR_QUERY_UTILS_HPP
|
||||
#define MATADOR_QUERY_UTILS_HPP
|
||||
|
||||
#include "table.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
#include <string>
|
||||
|
|
@ -12,6 +13,7 @@ namespace matador::query {
|
|||
class column;
|
||||
|
||||
[[nodiscard]] std::string prepare_identifier(const sql::dialect& d, const column &col);
|
||||
[[nodiscard]] std::string prepare_identifier(const sql::dialect& d, const table &tab, const column &col);
|
||||
[[nodiscard]] std::string prepare_criteria(const sql::dialect& d, const column &col);
|
||||
}
|
||||
#endif //MATADOR_QUERY_UTILS_HPP
|
||||
|
|
@ -30,7 +30,7 @@ public:
|
|||
[[nodiscard]] const std::string& alias() const;
|
||||
[[nodiscard]] const std::vector<class column>& columns() const;
|
||||
|
||||
[[nodiscard]] class column column(const std::string &name) const;
|
||||
// [[nodiscard]] class column column(const std::string &name) const;
|
||||
|
||||
operator const std::vector<query::column>&() const;
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
column operator ""_col(const char *name, size_t len) {
|
||||
column operator ""_col(const char *name, const size_t len) {
|
||||
const std::string str(name, len);
|
||||
const auto pos = str.find('.');
|
||||
if (pos == std::string::npos) {
|
||||
|
|
@ -18,7 +18,7 @@ column operator ""_col(const char *name, size_t len) {
|
|||
throw std::invalid_argument("Invalid column name: multiple dots found");
|
||||
}
|
||||
|
||||
return column{table{str.substr(0, pos)}, str.substr(pos + 1)};
|
||||
return column{std::make_shared<table>(str.substr(0, pos)), str.substr(pos + 1)};
|
||||
}
|
||||
|
||||
column::column(const char *name, const std::string& as)
|
||||
|
|
@ -27,30 +27,23 @@ column::column(const char *name, const std::string& as)
|
|||
|
||||
column::column(std::string name, std::string as)
|
||||
: table_(std::make_shared<query::table>())
|
||||
, name(std::move(name))
|
||||
, name_(std::move(name))
|
||||
, alias_(std::move(as)) {}
|
||||
|
||||
column::column(const sql::sql_function_t func, std::string name)
|
||||
: table_(std::make_shared<query::table>())
|
||||
, name(std::move(name))
|
||||
, name_(std::move(name))
|
||||
, function_(func) {}
|
||||
|
||||
column::column(const query::table& tab, std::string name, std::string as)
|
||||
: table_(std::make_shared<query::table>(tab))
|
||||
, name(std::move(name))
|
||||
, alias_(std::move(as)) {
|
||||
table_->columns_.push_back(*this);
|
||||
}
|
||||
|
||||
column::column(const std::shared_ptr<query::table>& t, std::string name, std::string as)
|
||||
: table_(t)
|
||||
, name(std::move(name))
|
||||
, name_(std::move(name))
|
||||
, alias_(std::move(as)) {
|
||||
}
|
||||
|
||||
bool column::equals(const column &x) const {
|
||||
return *table_ == *x.table_ &&
|
||||
name == x.name &&
|
||||
name_ == x.name_ &&
|
||||
alias_ == x.alias_ &&
|
||||
function_ == x.function_;
|
||||
}
|
||||
|
|
@ -60,18 +53,11 @@ column &column::as(std::string a) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
const std::string& column::column_name() const {
|
||||
return name;
|
||||
const std::string& column::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
std::string column::full_name() const {
|
||||
if (table_ && !table_->name().empty()) {
|
||||
return table_->name() + "." + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::string& column::alias_name() const {
|
||||
const std::string& column::alias() const {
|
||||
return alias_;
|
||||
}
|
||||
|
||||
|
|
@ -87,10 +73,6 @@ bool column::has_alias() const {
|
|||
return !alias_.empty();
|
||||
}
|
||||
|
||||
std::string column::alias() const {
|
||||
return alias_;
|
||||
}
|
||||
|
||||
std::shared_ptr<table> column::table() const {
|
||||
return table_;
|
||||
}
|
||||
|
|
@ -100,7 +82,7 @@ void column::table( const std::shared_ptr<query::table>& t ) {
|
|||
}
|
||||
|
||||
column::operator const std::string&() const {
|
||||
return name;
|
||||
return name_;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -39,8 +39,8 @@ std::string criteria_evaluator::evaluate(const abstract_criteria &node) {
|
|||
}
|
||||
|
||||
void criteria_evaluator::visit(const between_criteria &node) {
|
||||
query_.bind_vars.emplace_back(node.col().column_name());
|
||||
query_.bind_vars.emplace_back(node.col().column_name());
|
||||
query_.bind_vars.emplace_back(node.col().name());
|
||||
query_.bind_vars.emplace_back(node.col().name());
|
||||
clause_ += prepare_identifier(dialect_, node.col()) + " " + dialect_.token_at(sql::dialect_token::Between) + " ";
|
||||
evaluate_value(node.minimum());
|
||||
clause_ += " " + dialect_.token_at(sql::dialect_token::And) + " ";
|
||||
|
|
@ -51,7 +51,7 @@ template<class... Ts> struct overload : Ts... { using Ts::operator()...; };
|
|||
template<class... Ts> overload(Ts...) -> overload<Ts...>;
|
||||
|
||||
void criteria_evaluator::visit(const binary_criteria &node) {
|
||||
query_.bind_vars.emplace_back(node.col().column_name());
|
||||
query_.bind_vars.emplace_back(node.col().name());
|
||||
clause_ += prepare_criteria(dialect_, node.col()) + " " + detail::BinaryOperatorEnum.to_string(node.operand()) + " ";
|
||||
|
||||
evaluate_value(node.value());
|
||||
|
|
@ -64,7 +64,7 @@ void criteria_evaluator::visit( const binary_column_criteria& node ) {
|
|||
void criteria_evaluator::visit(const collection_criteria &node) {
|
||||
const auto count = node.values().size();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
query_.bind_vars.emplace_back(node.col().column_name());
|
||||
query_.bind_vars.emplace_back(node.col().name());
|
||||
}
|
||||
|
||||
clause_ += prepare_identifier(dialect_, node.col()) +
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ sql::query_context query_compiler::compile(const query_data &data,
|
|||
|
||||
std::string handle_column(sql::query_context &ctx, const sql::dialect *d, const query_data &data, const column &col) {
|
||||
if (col.is_function()) {
|
||||
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.column_name());
|
||||
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.name());
|
||||
ctx.prototype.back().change_type(utils::basic_type::type_int32);
|
||||
} else {
|
||||
ctx.prototype.emplace_back(col.column_name());
|
||||
ctx.prototype.emplace_back(col.name());
|
||||
}
|
||||
|
||||
if (const auto it = data.tables.find(col.table()->name()); it != data.tables.end()) {
|
||||
return prepare_identifier(*d, {it->second, col.column_name(), col.alias()});
|
||||
return prepare_identifier(*d, it->second, {col.name(), col.alias()});
|
||||
}
|
||||
|
||||
return prepare_identifier(*d, col);
|
||||
|
|
@ -69,13 +69,13 @@ void query_compiler::visit(internal::query_add_foreign_key_constraint_part& part
|
|||
|
||||
if (part.columns().size() < 2) {
|
||||
for (const auto &col: part.columns()) {
|
||||
query_.sql += dialect_->prepare_identifier_string(col.column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(col.name());
|
||||
}
|
||||
} else {
|
||||
auto it = part.columns().begin();
|
||||
query_.sql += dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(it->name());
|
||||
for (; it != part.columns().end(); ++it) {
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
|
||||
}
|
||||
}
|
||||
query_.sql += ")";
|
||||
|
|
@ -86,13 +86,13 @@ void query_compiler::visit(internal::query_add_primary_key_constraint_part& part
|
|||
|
||||
if (part.columns().size() < 2) {
|
||||
for (const auto &col: part.columns()) {
|
||||
query_.sql += dialect_->prepare_identifier_string(col.column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(col.name());
|
||||
}
|
||||
} else {
|
||||
auto it = part.columns().begin();
|
||||
query_.sql += dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(it->name());
|
||||
for (; it != part.columns().end(); ++it) {
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
|
||||
}
|
||||
}
|
||||
query_.sql += ")";
|
||||
|
|
@ -103,13 +103,13 @@ void query_compiler::visit(internal::query_add_foreign_key_reference_part& part)
|
|||
|
||||
if (part.columns().size() < 2) {
|
||||
for (const auto &col: part.columns()) {
|
||||
query_.sql += dialect_->prepare_identifier_string(col.column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(col.name());
|
||||
}
|
||||
} else {
|
||||
auto it = part.columns().begin();
|
||||
query_.sql += dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += dialect_->prepare_identifier_string(it->name());
|
||||
for (; it != part.columns().end(); ++it) {
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_name());
|
||||
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
|
||||
}
|
||||
}
|
||||
query_.sql += ")";
|
||||
|
|
@ -207,14 +207,14 @@ void query_compiler::visit(internal::query_into_part &part) {
|
|||
std::string result{"("};
|
||||
if (part.columns().size() < 2) {
|
||||
for (const auto &col: part.columns()) {
|
||||
result.append(dialect_->prepare_identifier_string(col.column_name()));
|
||||
result.append(dialect_->prepare_identifier_string(col.name()));
|
||||
}
|
||||
} else {
|
||||
auto it = part.columns().begin();
|
||||
result.append(dialect_->prepare_identifier_string((it++)->column_name()));
|
||||
result.append(dialect_->prepare_identifier_string((it++)->name()));
|
||||
for (; it != part.columns().end(); ++it) {
|
||||
result.append(", ");
|
||||
result.append(dialect_->prepare_identifier_string(it->column_name()));
|
||||
result.append(dialect_->prepare_identifier_string(it->name()));
|
||||
}
|
||||
}
|
||||
result += (")");
|
||||
|
|
@ -355,16 +355,16 @@ void query_compiler::visit(internal::query_set_part &part) {
|
|||
|
||||
value_visitor visitor(writer, query_); if (part.column_values().size() < 2) {
|
||||
for (const auto &column_value: part.column_values()) {
|
||||
result.append(dialect_->prepare_identifier_string(column_value.col().column_name()) + "=");
|
||||
result.append(dialect_->prepare_identifier_string(column_value.col().name()) + "=");
|
||||
result.append(determine_value(visitor, column_value.value()));
|
||||
}
|
||||
} else {
|
||||
auto it = part.column_values().begin();
|
||||
result.append(dialect_->prepare_identifier_string(it->col().column_name()) + "=");
|
||||
result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
result.append(determine_value(visitor, (it++)->value()));
|
||||
for (; it != part.column_values().end(); ++it) {
|
||||
result.append(", ");
|
||||
result.append(dialect_->prepare_identifier_string(it->col().column_name()) + "=");
|
||||
result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
result.append(determine_value(visitor, it->value()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,23 @@
|
|||
|
||||
namespace matador::query {
|
||||
std::string prepare_identifier( const sql::dialect& d, const column& col ) {
|
||||
std::string result;
|
||||
if (!col.is_function()) {
|
||||
if (!col.table()->name().empty()) {
|
||||
result = d.prepare_identifier_string(col.table()->has_alias() ? col.table()->alias() : col.table()->name()) + ".";
|
||||
}
|
||||
result += d.prepare_identifier_string(col.column_name());
|
||||
} else {
|
||||
result = d.sql_function_at(col.function()) + "(" + col.column_name() + ")";
|
||||
return prepare_identifier(d, *col.table(), col);
|
||||
}
|
||||
|
||||
std::string prepare_identifier( const sql::dialect& d, const table& tab, const column& col ) {
|
||||
std::string result;
|
||||
if (!col.is_function()) {
|
||||
if (!tab.name().empty()) {
|
||||
result = d.prepare_identifier_string(tab.has_alias() ? tab.alias() : tab.name()) + ".";
|
||||
}
|
||||
if (!col.alias().empty()) {
|
||||
result += " AS " + col.alias();
|
||||
}
|
||||
return result;
|
||||
result += d.prepare_identifier_string(col.name());
|
||||
} else {
|
||||
result = d.sql_function_at(col.function()) + "(" + col.name() + ")";
|
||||
}
|
||||
if (!col.alias().empty()) {
|
||||
result += " AS " + col.alias();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string prepare_criteria(const sql::dialect& d, const column& col) {
|
||||
|
|
@ -28,10 +32,10 @@ std::string prepare_criteria(const sql::dialect& d, const column& col) {
|
|||
if (!col.table()->name().empty()) {
|
||||
result = d.prepare_identifier_string(col.table()->has_alias() ? col.table()->alias() : col.table()->name()) + ".";
|
||||
}
|
||||
result += d.prepare_identifier_string(col.column_name());
|
||||
result += d.prepare_identifier_string(col.name());
|
||||
// }
|
||||
} else {
|
||||
result = d.sql_function_at(col.function()) + "(" + col.column_name() + ")";
|
||||
result = d.sql_function_at(col.function()) + "(" + col.name() + ")";
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ const std::vector<column>& table::columns() const {
|
|||
return columns_;
|
||||
}
|
||||
|
||||
column table::column( const std::string& name ) const {
|
||||
return {*this, name};
|
||||
}
|
||||
// column table::column(const std::string& name) const {
|
||||
// return {std::shared_ptr<table>(const_cast<table*>(this)), name};
|
||||
// }
|
||||
|
||||
table::operator const std::vector<query::column>&() const {
|
||||
return columns_;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue