small fixes for table, column and query_macro

This commit is contained in:
Sascha Kühl 2025-11-21 12:25:38 +01:00
parent e235c111a1
commit 34eaeca0bb
8 changed files with 25 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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 { \

View File

@ -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 ) {

View File

@ -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;
}
} }

View File

@ -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_;
} }