added meta table macro and removed unused query_macro
This commit is contained in:
parent
e768497cfd
commit
7cb64515bd
|
|
@ -1,9 +1,9 @@
|
|||
#include "matador/sql/connection.hpp"
|
||||
#include "matador/sql/query_macro.hpp"
|
||||
|
||||
#include "matador/query/criteria.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
|
@ -140,20 +140,20 @@ struct matador::utils::data_type_traits<job::job_mode, void> {
|
|||
}
|
||||
};
|
||||
|
||||
QUERY_HELPER(authors, AUTHOR, id, first_name, last_name, date_of_birth, year_of_birth, distinguished)
|
||||
META_TABLE(authors, AUTHOR, id, first_name, last_name, date_of_birth, year_of_birth, distinguished)
|
||||
|
||||
QUERY_HELPER(books, BOOK, id, author_id, title, published_in)
|
||||
META_TABLE(books, BOOK, id, author_id, title, published_in)
|
||||
|
||||
QUERY_HELPER(job, JOB, id, payload, type, description, state, mode)
|
||||
META_TABLE(job, JOB, id, payload, type, description, state, mode)
|
||||
|
||||
QUERY_HELPER(payload, PAYLOAD, id )
|
||||
META_TABLE(payload, PAYLOAD, id )
|
||||
|
||||
QUERY_HELPER(temporary_table, TEMPORARY_TABLE, id );
|
||||
META_TABLE(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)
|
||||
META_TABLE(customer, CUSTOMER, id, name, email, address)
|
||||
META_TABLE(product, PRODUCT, id, title, description, price, category)
|
||||
META_TABLE(category, CATEGORY, id, title, description)
|
||||
META_TABLE(cart, CART, id, items, owner)
|
||||
|
||||
int main() {
|
||||
using namespace matador::sql;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef MATADOR_META_TABLE_MACRO_HPP
|
||||
#define MATADOR_META_TABLE_MACRO_HPP
|
||||
|
||||
#include "matador/utils/macro_map.hpp"
|
||||
|
||||
#include "matador/query/table_column.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#define FIELD(FIELD_NAME) const matador::query::table_column& FIELD_NAME;
|
||||
#define INIT_FIELD(FIELD_NAME) , FIELD_NAME(*column_by_name(*this, #FIELD_NAME))
|
||||
#define FIELD_STRING(FIELD_NAME) #FIELD_NAME,
|
||||
|
||||
#define META_TABLE(TABLE_NAME, VARIABLE_NAME, ...) \
|
||||
namespace matador::query::meta { \
|
||||
namespace internal { \
|
||||
class TABLE_NAME##_table : public table { \
|
||||
public: \
|
||||
TABLE_NAME##_table() \
|
||||
: table(#TABLE_NAME, {MAP(FIELD_STRING, __VA_ARGS__)}) \
|
||||
MAP(INIT_FIELD, __VA_ARGS__) \
|
||||
{} \
|
||||
MAP(FIELD, __VA_ARGS__) \
|
||||
}; } \
|
||||
static const internal:: TABLE_NAME##_table VARIABLE_NAME; \
|
||||
}
|
||||
|
||||
#endif //MATADOR_META_TABLE_MACRO_HPP
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef QUERY_QUERY_HELPER_HPP
|
||||
#define QUERY_QUERY_HELPER_HPP
|
||||
|
||||
#include "matador/utils/macro_map.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#define FIELD(x) const matador::query::table_column x = create_column(*this, #x);
|
||||
|
||||
#define QUERY_HELPER(C, V, ...) \
|
||||
namespace matador::query::meta { \
|
||||
namespace internal { \
|
||||
class C##_table : public table { \
|
||||
public: \
|
||||
C##_table() : table(#C) {} \
|
||||
MAP(FIELD, __VA_ARGS__) \
|
||||
}; } \
|
||||
static const internal:: C##_table V; \
|
||||
}
|
||||
|
||||
#endif //QUERY_QUERY_HELPER_HPP
|
||||
|
|
@ -49,6 +49,7 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/query/internal/query_parts.hpp
|
||||
../../include/matador/query/join_data.hpp
|
||||
../../include/matador/query/key_value_generator.hpp
|
||||
../../include/matador/query/meta_table_macro.hpp
|
||||
../../include/matador/query/query.hpp
|
||||
../../include/matador/query/query_compiler.hpp
|
||||
../../include/matador/query/query_data.hpp
|
||||
|
|
@ -79,7 +80,6 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/sql/internal/query_result_impl.hpp
|
||||
../../include/matador/sql/internal/query_result_pk_resolver.hpp
|
||||
../../include/matador/sql/query_context.hpp
|
||||
../../include/matador/sql/query_macro.hpp
|
||||
../../include/matador/sql/query_result.hpp
|
||||
../../include/matador/sql/record.hpp
|
||||
../../include/matador/sql/sql_functions.hpp
|
||||
|
|
@ -160,6 +160,7 @@ add_library(matador-orm STATIC
|
|||
sql/record.cpp
|
||||
sql/statement.cpp
|
||||
sql/statement_cache.cpp
|
||||
../../include/matador/query/meta_table_macro.hpp
|
||||
)
|
||||
|
||||
target_include_directories(matador-orm
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ add_executable(OrmTests
|
|||
query/QueryFixture.cpp
|
||||
query/QueryFixture.hpp
|
||||
query/QueryTest.cpp
|
||||
sql/ColumnGeneratorTest.cpp
|
||||
query/ColumnGeneratorTest.cpp
|
||||
sql/ColumnTest.cpp
|
||||
sql/ConnectionPoolFixture.hpp
|
||||
sql/ConnectionPoolTest.cpp
|
||||
|
|
|
|||
|
|
@ -35,39 +35,6 @@ using namespace matador::utils;
|
|||
using namespace matador::sql;
|
||||
using namespace matador::test;
|
||||
|
||||
// #define FIELD(FIELD_NAME) const matador::query::column& FIELD_NAME = create_column(*this, #FIELD_NAME);
|
||||
//
|
||||
// #define META_TABLE(TABLE_NAME, VARIABLE_NAME, ...) \
|
||||
// namespace matador::query::meta { \
|
||||
// namespace internal { \
|
||||
// class TABLE_NAME##_table : public table { \
|
||||
// public: \
|
||||
// TABLE_NAME##_table() : table(#TABLE_NAME) {} \
|
||||
// MAP(FIELD, __VA_ARGS__) \
|
||||
// }; } \
|
||||
// static const internal:: TABLE_NAME##_table VARIABLE_NAME; \
|
||||
// }
|
||||
//
|
||||
// META_TABLE( books, BOOK, id, author_id, title, published_in )
|
||||
|
||||
class book_table : public table {
|
||||
public:
|
||||
book_table()
|
||||
: table("books", {"id", "title", "author_id"})
|
||||
, id(*column_by_name(*this, "id"))
|
||||
, title(*column_by_name(*this, "id"))
|
||||
, author_id(*column_by_name(*this, "author_id")) {
|
||||
}
|
||||
|
||||
const table_column& id;
|
||||
const table_column& title;
|
||||
const table_column& author_id;
|
||||
};
|
||||
|
||||
book_table BOOK;
|
||||
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager has one", "[query][entity][builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include <atomic>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <matador/query/query.hpp>
|
||||
|
||||
#include "matador/sql/connection_pool.hpp"
|
||||
#include "matador/sql/error_code.hpp"
|
||||
#include "matador/sql/statement_cache.hpp"
|
||||
|
|
@ -19,7 +17,6 @@
|
|||
|
||||
using namespace matador::test;
|
||||
using namespace matador::sql;
|
||||
using namespace matador::query;
|
||||
using namespace matador::utils;
|
||||
|
||||
class MetricsObserver {
|
||||
|
|
|
|||
Loading…
Reference in New Issue