query builder progress
This commit is contained in:
+56
-16
@@ -23,8 +23,11 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto obj = object_generator::generate<airplane>(repo, "airplane");
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -32,8 +35,11 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
|
||||
check_table_exists("airplane");
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
obj = object_generator::generate<flight>(repo, "flight");
|
||||
res = query::create()
|
||||
.table<flight>("flight", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -44,8 +50,11 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[query][where]") {
|
||||
REQUIRE(repo.attach<person>("person"));
|
||||
const auto obj = object_generator::generate<person>(repo, "person");
|
||||
auto res = query::create()
|
||||
.table<person>("person", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -99,10 +108,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
auto res = query::create()
|
||||
.table("person", {
|
||||
make_pk_column<uint32_t>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<std::string>("color", 63)
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", matador::utils::basic_type::type_uint32),
|
||||
attribute("name", matador::utils::basic_type::type_varchar, 255),
|
||||
attribute("color", matador::utils::basic_type::type_varchar, 63)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key("id")
|
||||
})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -144,8 +157,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto obj = object_generator::generate<airplane>(repo, "airplane");
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -153,8 +169,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
REQUIRE(db.exists("airplane"));
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
obj = object_generator::generate<flight>(repo, "flight");
|
||||
res = query::create()
|
||||
.table<flight>("flight", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -207,8 +226,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto obj = object_generator::generate<airplane>(repo, "airplane");
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -216,8 +238,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
REQUIRE(db.exists("airplane"));
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
obj = object_generator::generate<flight>(repo, "flight");
|
||||
res = query::create()
|
||||
.table<flight>("flight", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -297,8 +322,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
.and_then( [this] { return repo.attach<flight>("flight");} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto obj = object_generator::generate<airplane>(repo, "airplane");
|
||||
auto res = query::create()
|
||||
.table<airplane>("airplane", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -306,8 +334,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
REQUIRE(db.exists("airplane"));
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
obj = object_generator::generate<flight>(repo, "flight");
|
||||
res = query::create()
|
||||
.table<flight>("flight", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -386,8 +417,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
auto result = repo.attach<recipe>("recipes")
|
||||
.and_then( [this] { return repo.attach<ingredient>("ingredients"); } );
|
||||
|
||||
auto obj = object_generator::generate<recipe>(repo, "recipes");
|
||||
auto res = query::create()
|
||||
.table<recipe>("recipes", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -395,8 +429,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
REQUIRE(db.exists("recipes"));
|
||||
tables_to_drop.emplace("recipes");
|
||||
|
||||
obj = object_generator::generate<ingredient>(repo, "ingredients");
|
||||
res = query::create()
|
||||
.table<ingredient>("ingredients", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
@@ -404,8 +441,11 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
REQUIRE(db.exists("ingredients"));
|
||||
tables_to_drop.emplace("ingredients");
|
||||
|
||||
obj = object_generator::generate<recipe_ingredient>(repo, "recipe_ingredients");
|
||||
res = query::create()
|
||||
.table<recipe_ingredient>("recipe_ingredients", repo)
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 0);
|
||||
|
||||
Reference in New Issue
Block a user