renamed foreign class to entity, introduced interface class query_result_reader
This commit is contained in:
@@ -122,10 +122,10 @@ TEST_CASE("Select statement with foreign key", "[session]") {
|
||||
REQUIRE(res.first == 0);
|
||||
REQUIRE(res.second == R"(CREATE TABLE "flight" ("id" BIGINT, "airplane_id" BIGINT, "pilot_name" VARCHAR(255), CONSTRAINT PK_flight PRIMARY KEY (id), CONSTRAINT FK_flight_airplane_id FOREIGN KEY (airplane_id) REFERENCES airplane(id)))");
|
||||
|
||||
std::vector<foreign<airplane>> planes {
|
||||
make_foreign<airplane>(1, "Airbus", "A380"),
|
||||
make_foreign<airplane>(2, "Boeing", "707"),
|
||||
make_foreign<airplane>(3, "Boeing", "747")
|
||||
std::vector<entity<airplane>> planes {
|
||||
make_entity<airplane>(1, "Airbus", "A380"),
|
||||
make_entity<airplane>(2, "Boeing", "707"),
|
||||
make_entity<airplane>(3, "Boeing", "747")
|
||||
};
|
||||
|
||||
for (const auto &plane : planes) {
|
||||
@@ -136,13 +136,16 @@ TEST_CASE("Select statement with foreign key", "[session]") {
|
||||
auto count = s.select({count_all()}).from("airplane").fetch_value<int>();
|
||||
REQUIRE(count == 3);
|
||||
|
||||
flight f4711{4, *planes.begin(), "hans"};
|
||||
flight f4711{4, planes.at(1), "hans"};
|
||||
|
||||
res = s.insert().into<flight>("flight").values(f4711).execute();
|
||||
REQUIRE(res.first == 1);
|
||||
|
||||
auto f = *s.select<flight>().from("flight").fetch_all<flight>().begin();
|
||||
|
||||
REQUIRE(f.id == 4);
|
||||
REQUIRE(f.pilot_name == "hans");
|
||||
REQUIRE(f.airplane.get() != nullptr);
|
||||
REQUIRE(f.airplane->id == 2);
|
||||
|
||||
s.drop().table("flight").execute();
|
||||
s.drop().table("airplane").execute();
|
||||
|
||||
@@ -14,9 +14,9 @@ TEST_CASE("Extract values object", "[value extractor]") {
|
||||
p.units_in_stock = 100;
|
||||
p.unit_price = 49;
|
||||
p.quantity_per_unit = "pcs";
|
||||
p.category = make_foreign<matador::test::category>();
|
||||
p.category = make_entity<matador::test::category>();
|
||||
p.category->id = 7;
|
||||
p.supplier = make_foreign<matador::test::supplier>();;
|
||||
p.supplier = make_entity<matador::test::supplier>();;
|
||||
p.supplier->id = 13;
|
||||
p.product_name = "candle";
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/foreign.hpp"
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -21,7 +21,7 @@ struct airplane
|
||||
: id(id)
|
||||
, brand(std::move(b))
|
||||
, model(std::move(m)) {}
|
||||
unsigned long id;
|
||||
unsigned long id{};
|
||||
std::string brand;
|
||||
std::string model;
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/foreign.hpp"
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::test {
|
||||
|
||||
struct flight {
|
||||
unsigned long id;
|
||||
sql::foreign<test::airplane> airplane;
|
||||
unsigned long id{};
|
||||
sql::entity<test::airplane> airplane;
|
||||
std::string pilot_name;
|
||||
|
||||
template<class Operator>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/foreign.hpp"
|
||||
#include "matador/sql/entity.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace matador::test {
|
||||
struct product
|
||||
{
|
||||
std::string product_name;
|
||||
sql::foreign<test::supplier> supplier;
|
||||
sql::foreign<test::category> category;
|
||||
sql::entity<test::supplier> supplier;
|
||||
sql::entity<test::category> category;
|
||||
std::string quantity_per_unit;
|
||||
unsigned int unit_price;
|
||||
unsigned int units_in_stock;
|
||||
|
||||
Reference in New Issue
Block a user