Compare commits

..

No commits in common. "263c202c6986bcda9b6298ff1152195c1a88f5e5" and "2fcb504b9a1e1a8d740a7a778457cd3ec6008263" have entirely different histories.

34 changed files with 163 additions and 161 deletions

View File

@ -28,7 +28,7 @@ struct ingredient
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", matador::utils::fetch_type::Eager);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", matador::utils::fetch_type::EAGER);
}
};
@ -47,7 +47,7 @@ struct recipe
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", ingredients, matador::utils::fetch_type::Lazy);
field::has_many_to_many(op, "recipe_ingredients", ingredients, matador::utils::fetch_type::LAZY);
}
};

View File

@ -65,7 +65,7 @@ struct names {
void process(Operator &op) {
namespace field = matador::access;
field::primary_key( op, "id", id );
field::has_many(op, "name_list", names_list, "names_id", matador::utils::fetch_type::Eager);
field::has_many(op, "name_list", names_list, "names_id", matador::utils::fetch_type::EAGER);
}
};

View File

@ -39,7 +39,7 @@ struct CollectionCenter : core::Model {
field::attribute( op, "name", name, 511 );
field::attribute( op, "symbol", symbol );
field::attribute( op, "type", type );
field::has_many( op, "collection_center_users", users, "users_id", matador::utils::fetch_type::Lazy );
field::has_many( op, "collection_center_users", users, "users_id", matador::utils::fetch_type::LAZY );
}
};

View File

@ -53,7 +53,7 @@ struct Scenario : core::Model {
field::attribute( op, "description", description, 511 );
field::attribute( op, "symbol", symbol );
field::attribute( op, "state", state );
field::has_many( op, "collection_center", collection_center, "scenario_id", matador::utils::fetch_type::Lazy );
field::has_many( op, "collection_center", collection_center, "scenario_id", matador::utils::fetch_type::LAZY );
}
};
}

View File

@ -36,6 +36,7 @@ private:
std::string name_;
std::variant<class attribute*, std::string> attr_;
// class attribute* attr_{nullptr};
object *owner_{nullptr};
utils::constraints options_{utils::constraints::None};
std::string ref_table_name_{};

View File

@ -2,7 +2,9 @@
#define MATADOR_OBJECT_HPP
#include "matador/object/attribute.hpp"
// #include "matador/object/attribute_generator.hpp"
#include "matador/object/constraint.hpp"
// #include "matador/object/constraints_generator.hpp"
#include "matador/utils/identifier.hpp"

View File

@ -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(std::make_shared<query::table>(type_info.name()), type_info.primary_key_attribute()->name());
const query::column col(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()) {

View File

@ -113,7 +113,7 @@ public:
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Eager) {
if (attr.fetch() == utils::fetch_type::EAGER) {
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
if (!result) {
throw query_builder_exception{query_build_error::UnknownType};
@ -143,7 +143,7 @@ public:
template<class ContainerType>
void on_has_many_to_many(const char *id, ContainerType &/*cont*/, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &attr) {
if (attr.fetch() != utils::fetch_type::Eager) {
if (attr.fetch() != utils::fetch_type::EAGER) {
return;
}
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
@ -183,7 +183,7 @@ public:
template<class ContainerType>
void on_has_many_to_many(const char *id, ContainerType &/*cont*/, const utils::foreign_attributes &attr) {
if (attr.fetch() != utils::fetch_type::Eager) {
if (attr.fetch() != utils::fetch_type::EAGER) {
return;
}
const auto result = schema_.basic_info(typeid(typename ContainerType::value_type::value_type));
@ -258,7 +258,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
}
const auto foreign_table = std::make_shared<query::table>(info->get().name(), build_alias('t', ++table_index));
if (attr.fetch() == utils::fetch_type::Eager) {
if (attr.fetch() == utils::fetch_type::EAGER) {
auto next = processed_tables_.find(info->get().name());
if (next != processed_tables_.end()) {

View File

@ -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 = ""); // NOLINT(*-explicit-constructor)
column(sql::sql_function_t func, std::string name);
// column(const class table &tab, std::string name, std::string as = "");
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(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& name() const;
[[nodiscard]] const std::string& alias() const;
[[nodiscard]] const std::string& column_name() const;
[[nodiscard]] std::string full_name() const;
[[nodiscard]] const std::string& alias_name() 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};

View File

@ -88,7 +88,7 @@ public:
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
if (attr.fetch() == utils::fetch_type::LAZY || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
return;
}
if (!repo_) {
@ -111,7 +111,7 @@ public:
template<class ContainerType>
void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char *join_column, const char *inverse_join_column, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
if (attr.fetch() == utils::fetch_type::LAZY || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
return;
}
push(join_column);
@ -124,7 +124,7 @@ public:
private:
template<class Pointer>
void on_foreign_key(const char *id, Pointer &, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
if (attr.fetch() == utils::fetch_type::LAZY || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
push(id);
} else {
if (!repo_) {

View File

@ -1,7 +1,6 @@
#ifndef MATADOR_QUERY_UTILS_HPP
#define MATADOR_QUERY_UTILS_HPP
#include "table.hpp"
#include "matador/sql/dialect.hpp"
#include <string>
@ -13,7 +12,6 @@ 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

View File

@ -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:

View File

@ -109,14 +109,14 @@ public:
template<class ContainerType>
void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy) {
if (attr.fetch() == utils::fetch_type::LAZY) {
} else {}
}
template<class ContainerType>
void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy) {
if (attr.fetch() == utils::fetch_type::LAZY) {
} else {}
}
@ -124,7 +124,7 @@ public:
template<class ContainerType>
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/,
const utils::foreign_attributes &attr) {
if (attr.fetch() == utils::fetch_type::Lazy) {
if (attr.fetch() == utils::fetch_type::LAZY) {
// pk_reader_.read(*id, column_index_++);
} else {
const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type));
@ -197,7 +197,7 @@ private:
if (x.empty()) {
x.reset(new typename Pointer::value_type);
}
if (attr.fetch() == utils::fetch_type::Lazy) {
if (attr.fetch() == utils::fetch_type::LAZY) {
pk_reader_.read(*x, column_index_++);
} else {
const auto ti = std::type_index(typeid(*x));

View File

@ -57,7 +57,7 @@ public:
private:
template<class Type>
void on_foreign_key(const utils::fetch_type fetch) {
if (fetch == utils::fetch_type::Lazy) {
if (fetch == utils::fetch_type::LAZY) {
++column_index_;
} else {
const Type obj;

View File

@ -10,9 +10,10 @@ namespace matador::utils {
*
* Defines fetch types for foreign relations
*/
enum class fetch_type : uint8_t {
Lazy, /**< Indicates lazy fetch */
Eager /**< Indicates eager fetch */
enum class fetch_type : uint8_t
{
LAZY, /**< Indicates lazy fetch */
EAGER /**< Indicates eager fetch */
};
}

View File

@ -25,13 +25,12 @@ public:
private:
cascade_type cascade_{cascade_type::NONE};
fetch_type fetch_{fetch_type::Lazy};
fetch_type fetch_{fetch_type::LAZY};
};
const foreign_attributes CascadeNoneFetchLazy {};
const foreign_attributes CascadeNoneFetchEager {fetch_type::Eager};
const foreign_attributes CascadeAllFetchLazy {cascade_type::ALL, fetch_type::Lazy};
const foreign_attributes CascadeAllFetchEager {cascade_type::ALL, fetch_type::Eager};
const foreign_attributes CascadeAllFetchLazy {cascade_type::ALL, fetch_type::LAZY};
const foreign_attributes CascadeAllFetchEager {cascade_type::ALL, fetch_type::EAGER};
}

View File

@ -7,7 +7,7 @@
namespace matador::query {
column operator ""_col(const char *name, const size_t len) {
column operator ""_col(const char *name, 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, const size_t len) {
throw std::invalid_argument("Invalid column name: multiple dots found");
}
return column{std::make_shared<table>(str.substr(0, pos)), str.substr(pos + 1)};
return column{table{str.substr(0, pos)}, str.substr(pos + 1)};
}
column::column(const char *name, const std::string& as)
@ -27,23 +27,30 @@ 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_;
}
@ -53,11 +60,18 @@ column &column::as(std::string a) {
return *this;
}
const std::string& column::name() const {
return name_;
const std::string& column::column_name() const {
return name;
}
const std::string& column::alias() const {
std::string column::full_name() const {
if (table_ && !table_->name().empty()) {
return table_->name() + "." + name;
}
return name;
}
const std::string& column::alias_name() const {
return alias_;
}
@ -73,6 +87,10 @@ bool column::has_alias() const {
return !alias_.empty();
}
std::string column::alias() const {
return alias_;
}
std::shared_ptr<table> column::table() const {
return table_;
}
@ -82,7 +100,7 @@ void column::table( const std::shared_ptr<query::table>& t ) {
}
column::operator const std::string&() const {
return name_;
return name;
}
}

View File

@ -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().name());
query_.bind_vars.emplace_back(node.col().name());
query_.bind_vars.emplace_back(node.col().column_name());
query_.bind_vars.emplace_back(node.col().column_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().name());
query_.bind_vars.emplace_back(node.col().column_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().name());
query_.bind_vars.emplace_back(node.col().column_name());
}
clause_ += prepare_identifier(dialect_, node.col()) +

View File

@ -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.name());
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.column_name());
ctx.prototype.back().change_type(utils::basic_type::type_int32);
} else {
ctx.prototype.emplace_back(col.name());
ctx.prototype.emplace_back(col.column_name());
}
if (const auto it = data.tables.find(col.table()->name()); it != data.tables.end()) {
return prepare_identifier(*d, it->second, {col.name(), col.alias()});
return prepare_identifier(*d, {it->second, col.column_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.name());
query_.sql += dialect_->prepare_identifier_string(col.column_name());
}
} else {
auto it = part.columns().begin();
query_.sql += dialect_->prepare_identifier_string(it->name());
query_.sql += dialect_->prepare_identifier_string(it->column_name());
for (; it != part.columns().end(); ++it) {
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_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.name());
query_.sql += dialect_->prepare_identifier_string(col.column_name());
}
} else {
auto it = part.columns().begin();
query_.sql += dialect_->prepare_identifier_string(it->name());
query_.sql += dialect_->prepare_identifier_string(it->column_name());
for (; it != part.columns().end(); ++it) {
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_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.name());
query_.sql += dialect_->prepare_identifier_string(col.column_name());
}
} else {
auto it = part.columns().begin();
query_.sql += dialect_->prepare_identifier_string(it->name());
query_.sql += dialect_->prepare_identifier_string(it->column_name());
for (; it != part.columns().end(); ++it) {
query_.sql += ", " + dialect_->prepare_identifier_string(it->name());
query_.sql += ", " + dialect_->prepare_identifier_string(it->column_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.name()));
result.append(dialect_->prepare_identifier_string(col.column_name()));
}
} else {
auto it = part.columns().begin();
result.append(dialect_->prepare_identifier_string((it++)->name()));
result.append(dialect_->prepare_identifier_string((it++)->column_name()));
for (; it != part.columns().end(); ++it) {
result.append(", ");
result.append(dialect_->prepare_identifier_string(it->name()));
result.append(dialect_->prepare_identifier_string(it->column_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().name()) + "=");
result.append(dialect_->prepare_identifier_string(column_value.col().column_name()) + "=");
result.append(determine_value(visitor, column_value.value()));
}
} else {
auto it = part.column_values().begin();
result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
result.append(dialect_->prepare_identifier_string(it->col().column_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().name()) + "=");
result.append(dialect_->prepare_identifier_string(it->col().column_name()) + "=");
result.append(determine_value(visitor, it->value()));
}
}

View File

@ -4,23 +4,19 @@
namespace matador::query {
std::string prepare_identifier( const sql::dialect& d, const column& col ) {
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()) + ".";
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() + ")";
}
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;
if (!col.alias().empty()) {
result += " AS " + col.alias();
}
return result;
}
std::string prepare_criteria(const sql::dialect& d, const column& col) {
@ -32,10 +28,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.name());
result += d.prepare_identifier_string(col.column_name());
// }
} else {
result = d.sql_function_at(col.function()) + "(" + col.name() + ")";
result = d.sql_function_at(col.function()) + "(" + col.column_name() + ")";
}
return result;

View File

@ -49,9 +49,9 @@ const std::vector<column>& table::columns() const {
return columns_;
}
// column table::column(const std::string& name) const {
// return {std::shared_ptr<table>(const_cast<table*>(this)), name};
// }
column table::column( const std::string& name ) const {
return {*this, name};
}
table::operator const std::vector<query::column>&() const {
return columns_;

View File

@ -111,13 +111,12 @@ 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", basic_type::type_varchar, 255),
attribute("to", basic_type::type_varchar, 255)
attribute("from", matador::utils::basic_type::type_varchar, 255),
attribute("to", matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());
@ -126,7 +125,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
// check table description
std::vector<std::string> column_names = { "from", "to"};
std::vector types = {basic_type::type_varchar, basic_type::type_varchar};
std::vector<matador::utils::basic_type> types = {matador::utils::basic_type::type_varchar, matador::utils::basic_type::type_varchar};
const auto columns = db.describe("quotes");
REQUIRE(columns.is_ok());
@ -172,10 +171,9 @@ 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(dialect_token::StartQuote);
const auto end_quote = db.dialect().token_at(dialect_token::EndQuote);
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 std::string column_name = "name_with_" + start_quote + "open_close_quotes" + end_quote + "_in_backend_ctx";
@ -192,7 +190,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
auto res = query::create()
.table("quotes")
.columns({
attribute(name, basic_type::type_varchar, 255)
attribute(name, matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());
@ -203,7 +201,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
for (const auto &col : *columns) {
REQUIRE(col.name() == name);
REQUIRE(col.type() == basic_type::type_varchar);
REQUIRE(col.type() == matador::utils::basic_type::type_varchar);
}
res = query::drop()
@ -216,12 +214,11 @@ 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", basic_type::type_varchar, 255)
attribute("name", matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());

View File

@ -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());

View File

@ -32,7 +32,7 @@ struct names {
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::has_many(op, "name_list", names_list, "names_id", utils::fetch_type::Eager);
field::has_many(op, "name_list", names_list, "names_id", utils::fetch_type::EAGER);
}
};

View File

@ -30,7 +30,7 @@ struct author {
field::attribute(op, "date_of_birth", date_of_birth, 31);
field::attribute(op, "year_of_birth", year_of_birth);
field::attribute(op, "distinguished", distinguished);
field::has_many(op, "books", books, "author_id", utils::fetch_type::Lazy);
field::has_many(op, "books", books, "author_id", utils::fetch_type::LAZY);
}
};

View File

@ -23,7 +23,7 @@ struct book {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 511);
field::belongs_to(op, "author_id", book_author, utils::fetch_type::Eager);
field::belongs_to(op, "author_id", book_author, utils::fetch_type::EAGER);
field::attribute(op, "published_in", published_in);
}
};

View File

@ -21,7 +21,7 @@ struct department {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 63);
field::has_many(op, "employees", employees, "dep_id", utils::CascadeAllFetchEager);
field::has_many(op, "employees", employees, "dep_id", utils::fetch_type::EAGER);
// field::belongs_to(op, "manager_id", manager, utils::fetch_type::EAGER);
}
};
@ -38,7 +38,7 @@ struct employee {
field::primary_key(op, "id", id);
field::attribute(op, "first_name", first_name, 63);
field::attribute(op, "last_name", last_name, 63);
field::belongs_to(op, "dep_id", dep, utils::CascadeAllFetchLazy);
field::belongs_to(op, "dep_id", dep, utils::fetch_type::LAZY);
}
};

View File

@ -28,7 +28,7 @@ struct flight {
namespace field = matador::access;
using namespace matador::utils;
field::primary_key(op, "id", id);
field::belongs_to(op, "airplane_id", plane, {utils::cascade_type::ALL, fetch_type::Eager});
field::belongs_to(op, "airplane_id", plane, {utils::cascade_type::ALL, fetch_type::EAGER});
field::attribute(op, "pilot_name", pilot_name, 255);
}
};

View File

@ -42,7 +42,7 @@ struct order
field::attribute(op, "ship_region", ship_region, 255);
field::attribute(op, "ship_postal_code", ship_postal_code, 255);
field::attribute(op, "ship_country", ship_country, 255);
field::has_many(op, "order_details", order_details_, "order_id", utils::fetch_type::Eager);
field::has_many(op, "order_details", order_details_, "order_id", utils::fetch_type::EAGER);
}
};

View File

@ -27,7 +27,7 @@ struct ingredient
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::fetch_type::Eager);
field::has_many_to_many(op, "recipe_ingredients", recipes, "ingredient_id", "recipe_id", utils::fetch_type::EAGER);
}
};
@ -46,7 +46,7 @@ struct recipe
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::fetch_type::Lazy);
field::has_many_to_many(op, "recipe_ingredients", ingredients, utils::fetch_type::LAZY);
}
};

View File

@ -29,7 +29,7 @@ struct student {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "name", name, 255);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::fetch_type::Lazy);
field::has_many_to_many(op, "student_courses", courses, "student_id", "course_id", utils::fetch_type::LAZY);
}
};
@ -49,7 +49,7 @@ struct course {
namespace field = matador::access;
field::primary_key(op, "id", id);
field::attribute(op, "title", title, 255);
field::has_many_to_many(op, "student_courses", students, utils::fetch_type::Eager);
field::has_many_to_many(op, "student_courses", students, utils::fetch_type::EAGER);
}
};

View File

@ -46,14 +46,12 @@ 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) {
@ -94,18 +92,16 @@ 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) {
@ -160,24 +156,22 @@ 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) {
@ -218,13 +212,11 @@ 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) {
@ -266,13 +258,11 @@ 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) {

View File

@ -23,7 +23,7 @@ protected:
TEST_CASE_METHOD(CriteriaFixture, "Test binary criteria", "[criteria][binary]") {
const auto name_col = "name"_col;
REQUIRE(name_col.name() == "name");
REQUIRE(name_col.column_name() == "name");
auto clause = name_col != "george";

View File

@ -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].name());
REQUIRE(expected_columns[i] == columns[i].column_name());
}
}