small fixes for table, column and query_macro
This commit is contained in:
parent
e235c111a1
commit
34eaeca0bb
|
|
@ -154,6 +154,11 @@ QUERY_HELPER( payload, PAYLOAD, id )
|
||||||
|
|
||||||
QUERY_HELPER( temporary_table, TEMPORARY_TABLE, id );
|
QUERY_HELPER( temporary_table, TEMPORARY_TABLE, id );
|
||||||
|
|
||||||
|
QUERY_HELPER(customer, CUSTOMER, id, name, email, address)
|
||||||
|
QUERY_HELPER(product, PRODUCT, id, title, description, price, category)
|
||||||
|
QUERY_HELPER(category, CATEGORY, id, title, description)
|
||||||
|
QUERY_HELPER(cart, CART, id, items, owner)
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
using namespace matador::sql;
|
using namespace matador::sql;
|
||||||
using namespace matador::object;
|
using namespace matador::object;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ public:
|
||||||
[[nodiscard]] std::shared_ptr<table> table() const;
|
[[nodiscard]] std::shared_ptr<table> table() const;
|
||||||
void table(const std::shared_ptr<query::table>& t);
|
void table(const std::shared_ptr<query::table>& t);
|
||||||
|
|
||||||
|
operator const std::string&() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<query::table> table_;
|
std::shared_ptr<query::table> table_;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "matador/query/fk_value_extractor.hpp"
|
#include "matador/query/fk_value_extractor.hpp"
|
||||||
#include "matador/query/internal/column_value_pair.hpp"
|
#include "matador/query/internal/column_value_pair.hpp"
|
||||||
|
|
||||||
#include "matador/utils/foreign_attributes.hpp"
|
|
||||||
#include "matador/utils/primary_key_attribute.hpp"
|
#include "matador/utils/primary_key_attribute.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ public:
|
||||||
table() = default;
|
table() = default;
|
||||||
table(const char *name); // NOLINT(*-explicit-constructor)
|
table(const char *name); // NOLINT(*-explicit-constructor)
|
||||||
table(std::string name); // NOLINT(*-explicit-constructor)
|
table(std::string name); // NOLINT(*-explicit-constructor)
|
||||||
table(const char *name, std::string as); // NOLINT(*-explicit-constructor)
|
table(std::string name, std::string as);
|
||||||
table(std::string name, std::string as); // NOLINT(*-explicit-constructor)
|
|
||||||
table(std::string name, std::string as, const std::vector<column> &columns);
|
table(std::string name, std::string as, const std::vector<column> &columns);
|
||||||
|
|
||||||
table& as(const std::string &a);
|
table& as(const std::string &a);
|
||||||
|
|
@ -31,7 +30,9 @@ public:
|
||||||
[[nodiscard]] const std::string& alias() const;
|
[[nodiscard]] const std::string& alias() const;
|
||||||
[[nodiscard]] const std::vector<column>& columns() const;
|
[[nodiscard]] const std::vector<column>& columns() const;
|
||||||
|
|
||||||
operator const std::vector<column>&() const;
|
[[nodiscard]] column column(const std::string &name) const;
|
||||||
|
|
||||||
|
operator const std::vector<query::column>&() const;
|
||||||
private:
|
private:
|
||||||
friend class column;
|
friend class column;
|
||||||
|
|
||||||
|
|
@ -39,7 +40,7 @@ private:
|
||||||
std::string alias_;
|
std::string alias_;
|
||||||
|
|
||||||
std::string schema_name_;
|
std::string schema_name_;
|
||||||
std::vector<column> columns_;
|
std::vector<query::column> columns_;
|
||||||
};
|
};
|
||||||
|
|
||||||
table operator ""_tab(const char *name, size_t len);
|
table operator ""_tab(const char *name, size_t len);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#define FIELD(x) const column x{*this, #x, ""};
|
#define FIELD(x) const matador::query::column x{*this, #x, ""};
|
||||||
|
|
||||||
#define QUERY_HELPER(C, V, ...) \
|
#define QUERY_HELPER(C, V, ...) \
|
||||||
namespace matador::query::meta { \
|
namespace matador::query::meta { \
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ table_builder& table_builder::as( std::string table_alias ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
table_builder::operator class query::table() const {
|
table_builder::operator class query::table() const {
|
||||||
return {table_name, alias};
|
return {table_name, alias, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
constraint_builder& constraint_builder::constraint( std::string name ) {
|
constraint_builder& constraint_builder::constraint( std::string name ) {
|
||||||
|
|
|
||||||
|
|
@ -98,4 +98,9 @@ std::shared_ptr<table> column::table() const {
|
||||||
void column::table( const std::shared_ptr<query::table>& t ) {
|
void column::table( const std::shared_ptr<query::table>& t ) {
|
||||||
table_ = t;
|
table_ = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
column::operator const std::string&() const {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -10,17 +10,12 @@ table::table(std::string name)
|
||||||
: name_(std::move(name))
|
: name_(std::move(name))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
table::table(const char *name, std::string as)
|
|
||||||
: name_(name)
|
|
||||||
, alias_(std::move(as))
|
|
||||||
{}
|
|
||||||
|
|
||||||
table::table(std::string name, std::string as)
|
table::table(std::string name, std::string as)
|
||||||
: name_(std::move(name))
|
: name_(std::move(name))
|
||||||
, alias_(std::move(as))
|
, alias_(std::move(as))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
table::table( std::string name, std::string as, const std::vector<column>& columns )
|
table::table( std::string name, std::string as, const std::vector<query::column>& columns )
|
||||||
: name_(std::move(name))
|
: name_(std::move(name))
|
||||||
, alias_(std::move(as))
|
, alias_(std::move(as))
|
||||||
, columns_(columns) {}
|
, columns_(columns) {}
|
||||||
|
|
@ -54,7 +49,11 @@ const std::vector<column>& table::columns() const {
|
||||||
return columns_;
|
return columns_;
|
||||||
}
|
}
|
||||||
|
|
||||||
table::operator const std::vector<column>&() const {
|
column table::column( const std::string& name ) const {
|
||||||
|
return {*this, name};
|
||||||
|
}
|
||||||
|
|
||||||
|
table::operator const std::vector<query::column>&() const {
|
||||||
return columns_;
|
return columns_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue