renamed schema to repository
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "catch2/matchers/catch_matchers_string.hpp"
|
||||
|
||||
#include "matador/object/attribute_definition.hpp"
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
@@ -25,9 +25,9 @@ using namespace matador::object;
|
||||
using namespace matador::query;
|
||||
|
||||
TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][datatypes]" ) {
|
||||
REQUIRE(schema.attach<types>("types"));
|
||||
REQUIRE(repo.attach<types>("types"));
|
||||
auto res = query::create()
|
||||
.table<types>("types", schema)
|
||||
.table<types>("types", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -74,13 +74,13 @@ TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][da
|
||||
};
|
||||
|
||||
res = query::insert()
|
||||
.into("types", column_generator::generate<types>(schema, true))
|
||||
.into("types", column_generator::generate<types>(repo, true))
|
||||
.values(t)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto result = query::select<types>(schema)
|
||||
auto result = query::select<types>(repo)
|
||||
.from("types")
|
||||
.fetch_one<types>(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -278,9 +278,9 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||
TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]") {
|
||||
using namespace matador::sql;
|
||||
|
||||
REQUIRE(schema.attach<types>("types"));
|
||||
REQUIRE(repo.attach<types>("types"));
|
||||
const auto res = query::create()
|
||||
.table<types>("types", schema)
|
||||
.table<types>("types", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -351,9 +351,9 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
|
||||
using namespace matador::test::temporary;
|
||||
using namespace matador::sql;
|
||||
|
||||
REQUIRE(schema.attach<pk>("pk"));
|
||||
REQUIRE(repo.attach<pk>("pk"));
|
||||
auto res = query::create()
|
||||
.table<pk>("pk", schema)
|
||||
.table<pk>("pk", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -362,13 +362,13 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
|
||||
pk pk1{ 7, "george" };
|
||||
|
||||
res = query::insert()
|
||||
.into("pk", column_generator::generate<pk>(schema))
|
||||
.into("pk", column_generator::generate<pk>(repo))
|
||||
.values(pk1)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto row = query::select<pk>(schema)
|
||||
auto row = query::select<pk>(repo)
|
||||
.from("pk")
|
||||
.fetch_one<pk>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -380,9 +380,9 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
using namespace matador::test::temporary;
|
||||
using namespace matador::sql;
|
||||
|
||||
REQUIRE(schema.attach<pk>("pk"));
|
||||
REQUIRE(repo.attach<pk>("pk"));
|
||||
auto res = query::create()
|
||||
.table<pk>("pk", schema)
|
||||
.table<pk>("pk", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -391,7 +391,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
pk pk1{ 7, "george" };
|
||||
|
||||
auto stmt = query::insert()
|
||||
.into("pk", column_generator::generate<pk>(schema))
|
||||
.into("pk", column_generator::generate<pk>(repo))
|
||||
.values<pk>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -401,7 +401,7 @@ REQUIRE(stmt);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
stmt = query::select<pk>(schema)
|
||||
stmt = query::select<pk>(repo)
|
||||
.from("pk")
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace matador::test {
|
||||
|
||||
QueryFixture::QueryFixture()
|
||||
: db(connection::dns)
|
||||
, schema(db.dialect().default_schema_name())
|
||||
, repo(db.dialect().default_schema_name())
|
||||
{
|
||||
REQUIRE(db.open());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef MATADOR_QUERY_FIXTURE_HPP
|
||||
#define MATADOR_QUERY_FIXTURE_HPP
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
protected:
|
||||
sql::connection db;
|
||||
std::stack <std::string> tables_to_drop;
|
||||
object::schema schema;
|
||||
object::repository repo;
|
||||
|
||||
private:
|
||||
void drop_table_if_exists(const std::string &table_name) const;
|
||||
|
||||
@@ -19,9 +19,9 @@ using namespace matador::query;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") {
|
||||
REQUIRE(schema.attach<matador::test::person>("person"));
|
||||
REQUIRE(repo.attach<matador::test::person>("person"));
|
||||
auto stmt = query::create()
|
||||
.table<matador::test::person>("person", schema)
|
||||
.table<matador::test::person>("person", repo)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -43,9 +43,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][crea
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][insert]") {
|
||||
using namespace matador::test;
|
||||
|
||||
REQUIRE(schema.attach<person>("person"));
|
||||
REQUIRE(repo.attach<person>("person"));
|
||||
auto stmt = query::create()
|
||||
.table<person>("person", schema)
|
||||
.table<person>("person", repo)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
|
||||
person george{1, "george", 45, {1,2,3,4}};
|
||||
|
||||
stmt = query::insert()
|
||||
.into<person>("person", schema)
|
||||
.into<person>("person", repo)
|
||||
.values<person>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -69,7 +69,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto row = query::select<person>(schema)
|
||||
auto row = query::select<person>(repo)
|
||||
.from("person")
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -85,9 +85,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
using namespace matador::test;
|
||||
using namespace matador::utils;
|
||||
|
||||
REQUIRE(schema.attach<matador::test::person>("person"));
|
||||
REQUIRE(repo.attach<matador::test::person>("person"));
|
||||
auto stmt = query::create()
|
||||
.table<matador::test::person>("person", schema)
|
||||
.table<matador::test::person>("person", repo)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -101,7 +101,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
person george{1, "george", 45, {1,2,3,4}};
|
||||
|
||||
stmt = query::insert()
|
||||
.into<person>("person", schema)
|
||||
.into<person>("person", repo)
|
||||
.values<person>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -111,7 +111,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto row = query::select<person>(schema)
|
||||
auto row = query::select<person>(repo)
|
||||
.from("person")
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -136,7 +136,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
row = query::select<person>(schema)
|
||||
row = query::select<person>(repo)
|
||||
.from("person")
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -151,9 +151,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][delete]") {
|
||||
using namespace matador::test;
|
||||
|
||||
REQUIRE(schema.attach<matador::test::person>("person"));
|
||||
REQUIRE(repo.attach<matador::test::person>("person"));
|
||||
auto stmt = query::create()
|
||||
.table<matador::test::person>("person", schema)
|
||||
.table<matador::test::person>("person", repo)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -165,7 +165,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
check_table_exists("person");
|
||||
|
||||
stmt = query::insert()
|
||||
.into<person>("person", schema)
|
||||
.into<person>("person", repo)
|
||||
.values<person>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -185,7 +185,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
auto select_stmt = query::select<person>(schema)
|
||||
auto select_stmt = query::select<person>(repo)
|
||||
.from("person")
|
||||
.where("name"_col == matador::utils::_)
|
||||
.prepare(db);
|
||||
@@ -238,9 +238,9 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][statement][reuse]") {
|
||||
using namespace matador::test;
|
||||
|
||||
REQUIRE(schema.attach<matador::test::person>("person"));
|
||||
REQUIRE(repo.attach<matador::test::person>("person"));
|
||||
auto stmt = query::create()
|
||||
.table<matador::test::person>("person", schema)
|
||||
.table<matador::test::person>("person", repo)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
@@ -252,7 +252,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
|
||||
check_table_exists("person");
|
||||
|
||||
stmt = query::insert()
|
||||
.into<person>("person", schema)
|
||||
.into<person>("person", repo)
|
||||
.values<person>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -272,7 +272,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
stmt = query::select<person>(schema)
|
||||
stmt = query::select<person>(repo)
|
||||
.from("person")
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
+38
-38
@@ -20,12 +20,12 @@ using namespace matador::sql;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query][foreign][relation]") {
|
||||
auto result = schema.attach<airplane>("airplane")
|
||||
.and_then( [this] { return schema.attach<flight>("flight");} );
|
||||
auto result = repo.attach<airplane>("airplane")
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", schema)
|
||||
.table<airplane>("airplane", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -34,7 +34,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
.table<flight>("flight", schema)
|
||||
.table<flight>("flight", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -44,9 +44,9 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[query][where]") {
|
||||
REQUIRE(schema.attach<person>("person"));
|
||||
REQUIRE(repo.attach<person>("person"));
|
||||
auto res = query::create()
|
||||
.table<person>("person", schema)
|
||||
.table<person>("person", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -58,14 +58,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
george.image.emplace_back(37);
|
||||
|
||||
res = query::insert()
|
||||
.into("person", column_generator::generate<person>(schema, true))
|
||||
.into("person", column_generator::generate<person>(repo, true))
|
||||
.values(george)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
// fetch person as record
|
||||
auto result_record = query::select(column_generator::generate<person>(schema, true))
|
||||
auto result_record = query::select(column_generator::generate<person>(repo, true))
|
||||
.from("person")
|
||||
.where("id"_col == 7)
|
||||
.fetch_all(db);
|
||||
@@ -85,7 +85,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
}
|
||||
|
||||
// fetch person as person
|
||||
auto result_person = query::select(column_generator::generate<person>(schema, true))
|
||||
auto result_person = query::select(column_generator::generate<person>(repo, true))
|
||||
.from("person")
|
||||
.where("id"_col == 7)
|
||||
.fetch_all<person>(db);
|
||||
@@ -141,12 +141,12 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][foreign]") {
|
||||
auto result = schema.attach<airplane>("airplane")
|
||||
.and_then( [this] { return schema.attach<flight>("flight");} );
|
||||
auto result = repo.attach<airplane>("airplane")
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", schema)
|
||||
.table<airplane>("airplane", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -155,7 +155,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
.table<flight>("flight", schema)
|
||||
.table<flight>("flight", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -171,7 +171,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
res = query::insert()
|
||||
.into("airplane", column_generator::generate<airplane>(schema, true))
|
||||
.into("airplane", column_generator::generate<airplane>(repo, true))
|
||||
.values(*plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -187,13 +187,13 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
flight f4711{4, planes.at(1), "hans"};
|
||||
|
||||
res = query::insert()
|
||||
.into("flight", column_generator::generate<flight>(schema, true))
|
||||
.into("flight", column_generator::generate<flight>(repo, true))
|
||||
.values(f4711)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto f = query::select(column_generator::generate<flight>(schema, true))
|
||||
auto f = query::select(column_generator::generate<flight>(repo, true))
|
||||
.from("flight")
|
||||
.fetch_one(db);
|
||||
REQUIRE(f.is_ok());
|
||||
@@ -204,12 +204,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left", "[query][foreign][join_left]") {
|
||||
auto result = schema.attach<airplane>("airplane")
|
||||
.and_then( [this] { return schema.attach<flight>("flight");} );
|
||||
auto result = repo.attach<airplane>("airplane")
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", schema)
|
||||
.table<airplane>("airplane", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -218,7 +218,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
.table<flight>("flight", schema)
|
||||
.table<flight>("flight", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -234,7 +234,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
res = query::insert()
|
||||
.into("airplane", column_generator::generate<airplane>(schema, true))
|
||||
.into("airplane", column_generator::generate<airplane>(repo, true))
|
||||
.values(*plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -262,7 +262,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
REQUIRE(*res == 1);
|
||||
}
|
||||
|
||||
auto f = query::select(column_generator::generate<flight>(schema, true))
|
||||
auto f = query::select(column_generator::generate<flight>(repo, true))
|
||||
.from("flight")
|
||||
.fetch_one(db);
|
||||
REQUIRE(f.is_ok());
|
||||
@@ -294,12 +294,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single entity", "[query][join_left][find]") {
|
||||
auto result = schema.attach<airplane>("airplane")
|
||||
.and_then( [this] { return schema.attach<flight>("flight");} );
|
||||
auto result = repo.attach<airplane>("airplane")
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", schema)
|
||||
.table<airplane>("airplane", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -308,7 +308,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
.table<flight>("flight", schema)
|
||||
.table<flight>("flight", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -324,7 +324,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
res = query::insert()
|
||||
.into("airplane", column_generator::generate<airplane>(schema, true))
|
||||
.into("airplane", column_generator::generate<airplane>(repo, true))
|
||||
.values(*plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -347,14 +347,14 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
|
||||
for (const auto &f: flights) {
|
||||
res = query::insert()
|
||||
.into("flight", column_generator::generate<flight>(schema, true))
|
||||
.into("flight", column_generator::generate<flight>(repo, true))
|
||||
.values(*f)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
}
|
||||
|
||||
auto f = query::select(column_generator::generate<flight>(schema, true))
|
||||
auto f = query::select(column_generator::generate<flight>(repo, true))
|
||||
.from("flight")
|
||||
.fetch_one(db);
|
||||
REQUIRE(f.is_ok());
|
||||
@@ -384,12 +384,12 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship", "[query][join][many_to_many]") {
|
||||
auto result = schema.attach<recipe>("recipes")
|
||||
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } )
|
||||
.and_then( [this] { return schema.attach<recipe_ingredient>("recipe_ingredients"); } );
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } )
|
||||
.and_then( [this] { return repo.attach<recipe_ingredient>("recipe_ingredients"); } );
|
||||
|
||||
auto res = query::create()
|
||||
.table<recipe>("recipes", schema)
|
||||
.table<recipe>("recipes", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -398,7 +398,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
tables_to_drop.emplace("recipes");
|
||||
|
||||
res = query::create()
|
||||
.table<ingredient>("ingredients", schema)
|
||||
.table<ingredient>("ingredients", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -407,7 +407,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
tables_to_drop.emplace("ingredients");
|
||||
|
||||
res = query::create()
|
||||
.table<recipe_ingredient>("recipe_ingredients", schema)
|
||||
.table<recipe_ingredient>("recipe_ingredients", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -427,7 +427,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
|
||||
for (const auto &i: ingredients) {
|
||||
res = query::insert()
|
||||
.into("ingredients", column_generator::generate<ingredient>(schema, true))
|
||||
.into("ingredients", column_generator::generate<ingredient>(repo, true))
|
||||
.values(i)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -442,7 +442,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
|
||||
for (const auto &r: recipes) {
|
||||
res = query::insert()
|
||||
.into("recipes", column_generator::generate<recipe>(schema, true))
|
||||
.into("recipes", column_generator::generate<recipe>(repo, true))
|
||||
.values(r)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -462,7 +462,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
|
||||
for (const auto &ri: recipe_ingredients) {
|
||||
res = query::insert()
|
||||
.into("recipe_ingredients", column_generator::generate<recipe_ingredient>(schema, true))
|
||||
.into("recipe_ingredients", column_generator::generate<recipe_ingredient>(repo, true))
|
||||
.values({ri.first, ri.second})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
StatementTestFixture()
|
||||
{
|
||||
const auto res = query::create()
|
||||
.table<airplane>("airplane", schema)
|
||||
.table<airplane>("airplane", repo)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
tables_to_drop.emplace("airplane");
|
||||
@@ -49,11 +49,11 @@ protected:
|
||||
|
||||
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
|
||||
using namespace matador::utils;
|
||||
REQUIRE(schema.attach<airplane>("airplane"));
|
||||
REQUIRE(repo.attach<airplane>("airplane"));
|
||||
table ap{"airplane"};
|
||||
SECTION("Insert with prepared statement and placeholder") {
|
||||
auto stmt = query::insert()
|
||||
.into("airplane", column_generator::generate<airplane>(schema, true))
|
||||
.into("airplane", column_generator::generate<airplane>(repo, true))
|
||||
.values<airplane>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt.is_ok());
|
||||
@@ -65,7 +65,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
auto result = query::select(column_generator::generate<airplane>(schema, true))
|
||||
auto result = query::select(column_generator::generate<airplane>(repo, true))
|
||||
.from(ap)
|
||||
.fetch_all<airplane>(db);
|
||||
|
||||
@@ -81,14 +81,14 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
SECTION("Select with prepared statement") {
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
.into("airplane", column_generator::generate<airplane>(schema, true))
|
||||
.into("airplane", column_generator::generate<airplane>(repo, true))
|
||||
.values(*plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
}
|
||||
|
||||
auto stmt = query::select(column_generator::generate<airplane>(schema, true))
|
||||
auto stmt = query::select(column_generator::generate<airplane>(repo, true))
|
||||
.from(ap)
|
||||
.where("brand"_col == _)
|
||||
.prepare(db);
|
||||
|
||||
@@ -20,25 +20,25 @@ public:
|
||||
TypeTraitsTestFixture() {
|
||||
REQUIRE(db.open());
|
||||
const auto res = query::create()
|
||||
.table<location>("location", schema)
|
||||
.table<location>("location", repo)
|
||||
.execute(db);
|
||||
tables_to_drop.emplace("location");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]") {
|
||||
REQUIRE(schema.attach<location>("location"));
|
||||
REQUIRE(repo.attach<location>("location"));
|
||||
SECTION("Insert and select with direct execution") {
|
||||
location loc{1, "center", {1, 2, 3}, Color::Black};
|
||||
|
||||
auto res = query::insert()
|
||||
.into("location", column_generator::generate<location>(schema, true))
|
||||
.into("location", column_generator::generate<location>(repo, true))
|
||||
.values(loc)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto result = query::select(column_generator::generate<location>(schema, true))
|
||||
auto result = query::select(column_generator::generate<location>(repo, true))
|
||||
.from("location")
|
||||
.fetch_one<location>(db);
|
||||
|
||||
@@ -54,7 +54,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
|
||||
location loc{1, "center", {1, 2, 3}, Color::Black};
|
||||
|
||||
auto stmt = query::insert()
|
||||
.into("location", column_generator::generate<location>(schema, true))
|
||||
.into("location", column_generator::generate<location>(repo, true))
|
||||
.values<location>()
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -63,7 +63,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
|
||||
auto result = query::select(column_generator::generate<location>(schema, true))
|
||||
auto result = query::select(column_generator::generate<location>(repo, true))
|
||||
.from("location")
|
||||
.fetch_one<location>(db);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "../test/models/product.hpp"
|
||||
#include "../test/models/optional.hpp"
|
||||
@@ -10,7 +10,7 @@ using namespace matador::object;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("Generate column definitions from object", "[column][definition][generator]") {
|
||||
schema repo("main");
|
||||
repository repo("main");
|
||||
|
||||
auto result = repo.attach<matador::test::product>("products")
|
||||
.and_then([&repo] { return repo.attach<matador::test::supplier>("supplier"); })
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
|
||||
}
|
||||
|
||||
TEST_CASE("Generate columns from object with nullable columns", "[column generator]") {
|
||||
schema repo("main");
|
||||
repository repo("main");
|
||||
|
||||
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "../../models/department.hpp"
|
||||
|
||||
@@ -28,13 +28,13 @@ struct names {
|
||||
};
|
||||
|
||||
TEST_CASE("Test empty prototype tree", "[schema_node][empty]") {
|
||||
const object::schema tree;
|
||||
const object::repository tree;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
}
|
||||
|
||||
TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
|
||||
object::schema tree;
|
||||
object::repository tree;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
|
||||
@@ -50,7 +50,7 @@ TEST_CASE("Test add type to prototype tree", "[schema_node][add]") {
|
||||
}
|
||||
|
||||
TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous]") {
|
||||
object::schema tree;
|
||||
object::repository tree;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST_CASE("Test next and previous of schema node", "[schema_node][next][previous
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with foreign key", "[schema][relation_table][foreign_key]") {
|
||||
object::schema tree;
|
||||
object::repository tree;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
|
||||
@@ -75,7 +75,7 @@ TEST_CASE("Test automatic creating of a relation table with foreign key", "[sche
|
||||
}
|
||||
|
||||
TEST_CASE("Test automatic creating of a relation table with values", "[schema][relation_table][values]") {
|
||||
object::schema tree;
|
||||
object::repository tree;
|
||||
|
||||
REQUIRE( tree.empty() );
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ TEST_CASE("Create sql insert for entity with eager has one", "[query][entity][in
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<airplane>("airplanes")
|
||||
.and_then( [&scm] { return scm.attach<flight>("flights"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
@@ -32,7 +32,7 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<airplane>("airplanes")
|
||||
.and_then( [&scm] { return scm.attach<flight>("flights"); } );
|
||||
REQUIRE(result);
|
||||
@@ -77,7 +77,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<author>("authors")
|
||||
.and_then( [&scm] { return scm.attach<book>("books"); } );
|
||||
REQUIRE(result);
|
||||
@@ -137,7 +137,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<product>("products")
|
||||
.and_then( [&scm] { return scm.attach<order_details>("order_details"); } )
|
||||
.and_then( [&scm] { return scm.attach<supplier>("suppliers"); } )
|
||||
@@ -195,7 +195,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<recipe>("recipes")
|
||||
.and_then( [&scm] { return scm.attach<ingredient>("ingredients"); } );
|
||||
// .and_then( [&scm] { return scm.attach<recipe_ingredient>("recipe_ingredients"); } );
|
||||
@@ -240,7 +240,7 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<student>("students")
|
||||
.and_then( [&scm] { return scm.attach<course>("courses"); } );
|
||||
// .and_then( [&scm] { return scm.attach<student_course>("student_courses"); } );
|
||||
@@ -285,7 +285,7 @@ TEST_CASE("Test eager relationship", "[session][eager]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
schema scm("noop");
|
||||
repository scm("noop");
|
||||
auto result = scm.attach<department>("departments")
|
||||
.and_then( [&scm] { return scm.attach<employee>("employees"); } );
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "../test/models/product.hpp"
|
||||
#include "../test/models/order.hpp"
|
||||
@@ -14,7 +14,7 @@ using namespace matador::object;
|
||||
|
||||
TEST_CASE("Generate columns from object", "[column][generator]") {
|
||||
using namespace matador::test;
|
||||
schema s("main");
|
||||
repository s("main");
|
||||
auto result = s.attach<product>("product");
|
||||
REQUIRE( result );
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("Generate columns from object", "[column][generator]") {
|
||||
|
||||
TEST_CASE("Generate columns for object with has many relation", "[column][generator][relation]") {
|
||||
using namespace matador::test;
|
||||
schema s("main");
|
||||
repository s("main");
|
||||
auto result = s.attach<supplier>("supplier")
|
||||
.and_then( [&s] { return s.attach<category>("categories"); } )
|
||||
.and_then( [&s] { return s.attach<order_details>("order_details"); } )
|
||||
@@ -81,7 +81,7 @@ TEST_CASE("Generate columns for object with has many relation", "[column][genera
|
||||
|
||||
TEST_CASE("Generate columns for object with eager foreign key relation", "[column][generator][eager]") {
|
||||
using namespace matador::test;
|
||||
schema s("main");
|
||||
repository s("main");
|
||||
auto result = s.attach<book>("books")
|
||||
.and_then( [&s] { return s.attach<author>("authors"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
Reference in New Issue
Block a user