moved query macro generated class to namespace matador::query::meta
This commit is contained in:
parent
a146dce321
commit
e235c111a1
|
|
@ -3,6 +3,7 @@
|
||||||
#include "matador/sql/query_macro.hpp"
|
#include "matador/sql/query_macro.hpp"
|
||||||
|
|
||||||
#include "matador/query/criteria.hpp"
|
#include "matador/query/criteria.hpp"
|
||||||
|
#include "matador/query/query.hpp"
|
||||||
|
|
||||||
#include "matador/object/object_ptr.hpp"
|
#include "matador/object/object_ptr.hpp"
|
||||||
#include "matador/object/repository.hpp"
|
#include "matador/object/repository.hpp"
|
||||||
|
|
@ -143,20 +144,21 @@ struct matador::utils::data_type_traits<job::job_mode, void> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QUERY_HELPER( authors, id, first_name, last_name, date_of_birth, year_of_birth, distinguished )
|
QUERY_HELPER( authors, AUTHOR, id, first_name, last_name, date_of_birth, year_of_birth, distinguished )
|
||||||
|
|
||||||
QUERY_HELPER( books, id, author_id, title, published_in )
|
QUERY_HELPER( books, BOOK, id, author_id, title, published_in )
|
||||||
|
|
||||||
QUERY_HELPER( job, id, payload, type, description, state, mode )
|
QUERY_HELPER( job, JOB, id, payload, type, description, state, mode )
|
||||||
|
|
||||||
QUERY_HELPER( payload, id )
|
QUERY_HELPER( payload, PAYLOAD, id )
|
||||||
|
|
||||||
QUERY_HELPER( temporary_table, id );
|
QUERY_HELPER( temporary_table, TEMPORARY_TABLE, id );
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
using namespace matador::sql;
|
using namespace matador::sql;
|
||||||
using namespace matador::object;
|
using namespace matador::object;
|
||||||
using namespace matador::utils;
|
using namespace matador::utils;
|
||||||
|
using namespace matador::query::meta;
|
||||||
|
|
||||||
const std::string env_var{"MATADOR_BACKENDS_PATH"};
|
const std::string env_var{"MATADOR_BACKENDS_PATH"};
|
||||||
|
|
||||||
|
|
@ -233,19 +235,20 @@ int main() {
|
||||||
// .values( {3, "Misery", mc.id, 1984} )
|
// .values( {3, "Misery", mc.id, 1984} )
|
||||||
// .execute();
|
// .execute();
|
||||||
//
|
//
|
||||||
// auto select_books_sql = c.query( s )
|
auto select_books_sql = matador::query::query::select( BOOK, {AUTHOR.last_name} )
|
||||||
// .select( qh::books.columns, {qh::authors.last_name} )
|
.from( BOOK )
|
||||||
// .from( qh::books )
|
.join_left( AUTHOR )
|
||||||
// .join_left( qh::authors )
|
.on( BOOK.author_id == AUTHOR.id )
|
||||||
// .on( qh::books.author_id == qh::authors.id )
|
.where( BOOK.published_in < 2008 && AUTHOR.last_name == "King" )
|
||||||
// .where( qh::books.published_in < 2008 && qh::authors.last_name == "King" )
|
.group_by( BOOK.published_in )
|
||||||
// .group_by( qh::books.published_in )
|
.order_by( BOOK.title ).asc()
|
||||||
// .order_by( qh::books.title ).asc()
|
.limit( 5 )
|
||||||
// .limit( 5 )
|
.offset( 2 )
|
||||||
// .offset( 2 )
|
.fetch_all(c);
|
||||||
// .fetch_all();
|
|
||||||
//
|
for (const auto& r: *select_books_sql) {
|
||||||
// for (const auto& r: select_books_sql) { std::cout << "R: " << r.at( qh::books.title ) << ", " << r.at( qh::authors.last_name ) << "\n"; }
|
std::cout << "R: " << r.at( BOOK.title ) << ", " << r.at( AUTHOR.last_name ) << "\n";
|
||||||
|
}
|
||||||
// // SELECT book.title, book.id, book.author_id, book.published_in, author.name
|
// // SELECT book.title, book.id, book.author_id, book.published_in, author.name
|
||||||
// // FROM book
|
// // FROM book
|
||||||
// // INNER JOIN author ON book.author_id = author.id
|
// // INNER JOIN author ON book.author_id = author.id
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ public:
|
||||||
[[nodiscard]] const std::string& name() const;
|
[[nodiscard]] const std::string& name() const;
|
||||||
[[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;
|
||||||
private:
|
private:
|
||||||
friend class column;
|
friend class column;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#define FIELD(x) const query::column x{*this, #x, ""};
|
#define FIELD(x) const column x{*this, #x, ""};
|
||||||
|
|
||||||
#define QUERY_HELPER(C, ...) \
|
#define QUERY_HELPER(C, V, ...) \
|
||||||
namespace matador::qh { \
|
namespace matador::query::meta { \
|
||||||
namespace internal { \
|
namespace internal { \
|
||||||
struct C##_query : query::table { \
|
struct C##_query : table { \
|
||||||
C##_query() : table(#C) {} \
|
C##_query() : table(#C) {} \
|
||||||
MAP(FIELD, __VA_ARGS__) \
|
MAP(FIELD, __VA_ARGS__) \
|
||||||
}; } \
|
}; } \
|
||||||
static const internal:: C##_query C; \
|
static const internal:: C##_query V; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //QUERY_QUERY_HELPER_HPP
|
#endif //QUERY_QUERY_HELPER_HPP
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,10 @@ const std::vector<column>& table::columns() const {
|
||||||
return columns_;
|
return columns_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table::operator const std::vector<column>&() const {
|
||||||
|
return columns_;
|
||||||
|
}
|
||||||
|
|
||||||
table operator ""_tab(const char *name, size_t len) {
|
table operator ""_tab(const char *name, size_t len) {
|
||||||
return {{name, len}};
|
return {{name, len}};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue