add column info (progress, not compiling)
This commit is contained in:
@@ -13,6 +13,8 @@ add_executable(tests QueryBuilderTest.cpp
|
||||
ConnectionPoolTest.cpp
|
||||
BackendProviderTest.cpp
|
||||
models/product.hpp
|
||||
models/order.hpp
|
||||
models/order_details.h
|
||||
ColumnGeneratorTest.cpp
|
||||
ColumnNameGeneratorTest.cpp
|
||||
ValueGeneratorTest.cpp
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/sql/table_repository.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
|
||||
#include "models/product.hpp"
|
||||
#include "models/optional.hpp"
|
||||
@@ -10,7 +10,7 @@ using namespace matador::sql;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("Generate columns from object", "[column generator]") {
|
||||
table_repository repo;
|
||||
schema repo;
|
||||
|
||||
auto columns = column_generator::generate<matador::test::product>(repo);
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST_CASE("Generate columns from object", "[column generator]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
|
||||
table_repository repo;
|
||||
schema repo;
|
||||
|
||||
auto columns = column_generator::generate<matador::test::optional>(repo);
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/column_name_generator.hpp"
|
||||
#include "matador/sql/schema.hpp"
|
||||
|
||||
#include "models/order.hpp"
|
||||
#include "models/product.hpp"
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Generate column names from object", "[column name generator]") {
|
||||
schema s;
|
||||
s.attach<matador::test::product>("product");
|
||||
|
||||
auto columns = column_name_generator::generate<matador::test::product>();
|
||||
auto columns = column_name_generator::generate<matador::test::product>(s);
|
||||
|
||||
const std::vector<std::string> expected_columns = {
|
||||
"product_name",
|
||||
@@ -25,6 +29,40 @@ TEST_CASE("Generate column names from object", "[column name generator]") {
|
||||
REQUIRE(columns.size() == expected_columns.size());
|
||||
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
REQUIRE(expected_columns[i] == columns[i]);
|
||||
REQUIRE(expected_columns[i] == columns[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Generate column names for object with has many relation", "[column][relation]") {
|
||||
schema s;
|
||||
s.attach<matador::test::product>("product");
|
||||
s.attach<matador::test::order_details>("order_details");
|
||||
s.attach<matador::test::order>("order");
|
||||
|
||||
auto columns = column_name_generator::generate<matador::test::order>(s);
|
||||
|
||||
const std::vector<std::string> expected_columns = {
|
||||
"order_id",
|
||||
"order_date",
|
||||
"required_date",
|
||||
"shipped_date",
|
||||
"ship_via",
|
||||
"freight",
|
||||
"ship_name",
|
||||
"ship_address",
|
||||
"ship_city",
|
||||
"ship_region",
|
||||
"ship_postal_code",
|
||||
"ship_country",
|
||||
"order_details_id",
|
||||
"order_id",
|
||||
"product_id",
|
||||
};
|
||||
REQUIRE(!columns.empty());
|
||||
REQUIRE(columns.size() == expected_columns.size());
|
||||
|
||||
for (size_t i = 0; i != expected_columns.size(); ++i) {
|
||||
REQUIRE(expected_columns[i] == columns[i].name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -164,7 +164,7 @@ TEST_CASE("Create, insert and select a blob column", "[query][blob]") {
|
||||
REQUIRE(q.table_name == "person");
|
||||
|
||||
q = query.insert().into("person", {
|
||||
"id", "name", "data"
|
||||
{"", "id", ""}, {"", "name", ""}, {"", "data", ""}
|
||||
}).values({7UL, "george", blob{1, 'A', 3, 4}}).compile();
|
||||
|
||||
REQUIRE(q.sql == R"(INSERT INTO "person" ("id", "name", "data") VALUES (7, 'george', X'01410304'))");
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef QUERY_ORDER_HPP
|
||||
#define QUERY_ORDER_HPP
|
||||
|
||||
#include "order_details.h"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct order
|
||||
{
|
||||
unsigned long order_id{};
|
||||
std::string order_date;
|
||||
std::string required_date;
|
||||
std::string shipped_date;
|
||||
unsigned int ship_via{};
|
||||
unsigned int freight{};
|
||||
std::string ship_name;
|
||||
std::string ship_address;
|
||||
std::string ship_city;
|
||||
std::string ship_region;
|
||||
std::string ship_postal_code;
|
||||
std::string ship_country;
|
||||
std::vector<sql::entity<order_details>> order_details_;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
field::primary_key(op, "order_id", order_id);
|
||||
field::attribute(op, "order_date", order_date, 255);
|
||||
field::attribute(op, "required_date", required_date, 255);
|
||||
field::attribute(op, "shipped_date", shipped_date, 255);
|
||||
field::attribute(op, "ship_via", ship_via);
|
||||
field::attribute(op, "freight", freight);
|
||||
field::attribute(op, "ship_name", ship_name, 255);
|
||||
field::attribute(op, "ship_address", ship_address, 255);
|
||||
field::attribute(op, "ship_city", ship_city, 255);
|
||||
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_, fetch_type::EAGER);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_ORDER_HPP
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef QUERY_ORDER_DETAILS_H
|
||||
#define QUERY_ORDER_DETAILS_H
|
||||
|
||||
#include "product.hpp"
|
||||
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct order;
|
||||
|
||||
struct order_details
|
||||
{
|
||||
unsigned long order_details_id;
|
||||
sql::entity<order> order_;
|
||||
sql::entity<product> product_;
|
||||
|
||||
template<class Operator>
|
||||
void process(Operator &op) {
|
||||
namespace field = matador::utils::access;
|
||||
field::primary_key(op, "order_details_id", order_details_id);
|
||||
field::belongs_to(op, "order_id", order_, utils::default_foreign_attributes);
|
||||
field::has_one(op, "product_id", product_, utils::default_foreign_attributes);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_ORDER_DETAILS_H
|
||||
Reference in New Issue
Block a user