removed class query and moved their static methods to simple functions
This commit is contained in:
@@ -68,14 +68,14 @@ TEST_CASE_METHOD(QueryFixture, "Insert and select basic datatypes", "[query][dat
|
||||
blob_val
|
||||
};
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into("types", generator::columns<types>(repo))
|
||||
.values(t)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select<types>(repo)
|
||||
auto result = select<types>(repo)
|
||||
.from("types")
|
||||
.fetch_one<types>(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -102,7 +102,7 @@ TEST_CASE_METHOD(QueryFixture, "Insert and select basic datatypes", "[query][dat
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][identifier]" ) {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute("from", basic_type::Varchar, 255),
|
||||
@@ -126,14 +126,14 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||
++i;
|
||||
}
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("quotes", {"from", "to"})
|
||||
.values({"Berlin", "London"})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({"from", "to"})
|
||||
auto row = select({"from", "to"})
|
||||
.from("quotes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -142,7 +142,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||
REQUIRE(row.value()->at("from").as<std::string>() == "Berlin");
|
||||
REQUIRE(row.value()->at("to").as<std::string>() == "London");
|
||||
|
||||
res = query::update("quotes")
|
||||
res = update("quotes")
|
||||
.set("from", "Hamburg")
|
||||
.set("to", "New York")
|
||||
.where("from"_col == "Berlin")
|
||||
@@ -150,7 +150,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({"from", "to"})
|
||||
row = select({"from", "to"})
|
||||
.from("quotes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -176,7 +176,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
tables_to_drop.emplace("quotes");
|
||||
|
||||
for (const auto &name : column_names) {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
attribute(name, basic_type::Varchar, 255)
|
||||
@@ -193,7 +193,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
REQUIRE(col.type() == basic_type::Varchar);
|
||||
}
|
||||
|
||||
res = query::drop()
|
||||
res = drop()
|
||||
.table("quotes")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -202,7 +202,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("escapes")
|
||||
.columns({
|
||||
attribute("name", basic_type::Varchar, 255)
|
||||
@@ -212,14 +212,14 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||
REQUIRE(res->affected_rows == 0);
|
||||
tables_to_drop.emplace("escapes");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("escapes", {"name"})
|
||||
.values({"text"})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({"name"})
|
||||
auto row = select({"name"})
|
||||
.from("escapes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -227,13 +227,13 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||
REQUIRE(row->has_value());
|
||||
REQUIRE(row.value()->at("name").as<std::string>() == "text");
|
||||
|
||||
res = query::update("escapes")
|
||||
res = update("escapes")
|
||||
.set("name", "text'd")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({"name"})
|
||||
row = select({"name"})
|
||||
.from("escapes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -241,13 +241,13 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||
REQUIRE(row->has_value());
|
||||
REQUIRE(row.value()->at("name").as<std::string>() == "text'd");
|
||||
|
||||
res = query::update("escapes")
|
||||
res = update("escapes")
|
||||
.set("name", "text\nhello\tworld")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({"name"})
|
||||
row = select({"name"})
|
||||
.from("escapes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -255,13 +255,13 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||
REQUIRE(row->has_value());
|
||||
REQUIRE(row.value()->at("name").as<std::string>() == "text\nhello\tworld");
|
||||
|
||||
res = query::update("escapes")
|
||||
res = update("escapes")
|
||||
.set("name", "text \"text\"")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({"name"})
|
||||
row = select({"name"})
|
||||
.from("escapes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -317,7 +317,7 @@ TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]"
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test unknown table", "[query][table]") {
|
||||
const auto result = query::select({"name"})
|
||||
const auto result = select({"name"})
|
||||
.from("person")
|
||||
.fetch_all(db);
|
||||
|
||||
@@ -346,14 +346,14 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
|
||||
|
||||
pk pk1{ 7, "george" };
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into("pk", generator::columns<pk>(repo))
|
||||
.values(pk1)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select<pk>(repo)
|
||||
auto row = select<pk>(repo)
|
||||
.from("pk")
|
||||
.fetch_one<pk>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -369,7 +369,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
|
||||
pk pk1{ 7, "george" };
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into("pk", generator::columns<pk>(repo))
|
||||
.values(generator::placeholders<pk>())
|
||||
.prepare(db);
|
||||
@@ -380,7 +380,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
stmt = query::select<pk>(repo)
|
||||
stmt = select<pk>(repo)
|
||||
.from("pk")
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
@@ -415,7 +415,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// using namespace matador::test::temporary;
|
||||
// using namespace matador::sql;
|
||||
// REQUIRE(schema.attach<appointment>("appointment"));
|
||||
// auto res = query::create()
|
||||
// auto res = create()
|
||||
// .table<appointment>("appointment", schema)
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
@@ -426,14 +426,14 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// auto time_str = matador::utils::to_string(dinner.time_point);
|
||||
// auto date_str = matador::utils::to_string(dinner.date_point);
|
||||
//
|
||||
// res = query::insert()
|
||||
// res = insert()
|
||||
// .into("appointment", column_generator::generate<appointment>(schema))
|
||||
// .values(dinner)
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
// REQUIRE(res->affected_rows == 1);
|
||||
//
|
||||
// auto row = query::select<appointment>(schema)
|
||||
// auto row = select<appointment>(schema)
|
||||
// .from("appointment")
|
||||
// .fetch_one<appointment>(db);
|
||||
// REQUIRE(row.is_ok());
|
||||
@@ -446,7 +446,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// TEST_CASE_METHOD(QueryFixture, "Test null column", "[query][select][null]") {
|
||||
// using namespace matador::sql;
|
||||
//
|
||||
// auto res = query::create()
|
||||
// auto res = create()
|
||||
// .table("person", {
|
||||
// make_pk_column<unsigned long>("id"),
|
||||
// make_column<std::string>("first_name", 255, null_option::NULLABLE),
|
||||
@@ -457,21 +457,21 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// REQUIRE(res->affected_rows == 0);
|
||||
// tables_to_drop.emplace("person");
|
||||
//
|
||||
// res = query::insert()
|
||||
// res = insert()
|
||||
// .into("person", {"id", "first_name"})
|
||||
// .values({1, "george"})
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
// REQUIRE(res->affected_rows == 1);
|
||||
//
|
||||
// res = query::insert()
|
||||
// res = insert()
|
||||
// .into("person", {"id", "last_name"})
|
||||
// .values({2, "clooney"})
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
// REQUIRE(res->affected_rows == 1);
|
||||
//
|
||||
// auto result = query::select({"id", "first_name", "last_name"})
|
||||
// auto result = select({"id", "first_name", "last_name"})
|
||||
// .from("person")
|
||||
// .fetch_all(db);
|
||||
// REQUIRE(result.is_ok());
|
||||
@@ -491,7 +491,7 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// TEST_CASE_METHOD(QueryFixture, "Test null column prepared", "[query][select][null][prepared]") {
|
||||
// using namespace matador::sql;
|
||||
//
|
||||
// auto res = query::create()
|
||||
// auto res = create()
|
||||
// .table("person", {
|
||||
// make_pk_column<unsigned long>("id"),
|
||||
// make_column<std::string>("first_name", 255, null_option::NULLABLE),
|
||||
@@ -502,21 +502,21 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
|
||||
// REQUIRE(res->affected_rows == 0);
|
||||
// tables_to_drop.emplace("person");
|
||||
//
|
||||
// res = query::insert()
|
||||
// res = insert()
|
||||
// .into("person", {"id", "first_name"})
|
||||
// .values({1, "george"})
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
// REQUIRE(res->affected_rows == 1);
|
||||
//
|
||||
// res = query::insert()
|
||||
// res = insert()
|
||||
// .into("person", {"id", "last_name"})
|
||||
// .values({2, "clooney"})
|
||||
// .execute(db);
|
||||
// REQUIRE(res.is_ok());
|
||||
// REQUIRE(res->affected_rows == 1);
|
||||
//
|
||||
// auto result = query::select({"id", "first_name", "last_name"})
|
||||
// auto result = select({"id", "first_name", "last_name"})
|
||||
// .from("person")
|
||||
// .fetch_all(db);
|
||||
// REQUIRE(result.is_ok());
|
||||
|
||||
@@ -39,7 +39,7 @@ void QueryFixture::check_table_not_exists(const std::string &table_name) const {
|
||||
void QueryFixture::drop_table_if_exists(const std::string &table_name) const {
|
||||
const auto result = db.exists(table_name).and_then([&table_name, this](const bool exists) {
|
||||
if (exists) {
|
||||
auto res = query::query::drop()
|
||||
auto res = query::drop()
|
||||
.table(table_name)
|
||||
.execute(db);
|
||||
REQUIRE(res);
|
||||
|
||||
@@ -26,7 +26,7 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
|
||||
const table tab("types");
|
||||
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table(tab)
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -90,14 +90,14 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
time_type_t mt{12, 34, 56};
|
||||
blob_type_t bin{0x01,0x02,0x03,0x04};
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("types", cols)
|
||||
.values({id, c, s, i, ll, uc, us, ui, ull, b, f, d, str, varchar, md, mt, bin})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select(cols)
|
||||
auto result = select(cols)
|
||||
.from("types")
|
||||
.fetch_one(db);
|
||||
|
||||
@@ -127,7 +127,7 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][record]")
|
||||
{
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -144,7 +144,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][recor
|
||||
check_table_exists("person");
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::drop()
|
||||
res = drop()
|
||||
.table("person")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -155,7 +155,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][recor
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Create table with identity primary key", "[query][record][create][identity]") {
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32).primary_key().identity(),
|
||||
@@ -169,7 +169,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with identity primary key", "[query
|
||||
check_table_exists("person");
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::drop()
|
||||
res = drop()
|
||||
.table("person")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -180,7 +180,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with identity primary key", "[query
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key", "[query][record]")
|
||||
{
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("airplane")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -197,7 +197,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||
check_table_exists("airplane");
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
res = create()
|
||||
.table("flight")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -215,7 +215,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||
check_table_exists("flight");
|
||||
tables_to_drop.emplace("flight");
|
||||
|
||||
res = query::drop()
|
||||
res = drop()
|
||||
.table("flight")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -223,7 +223,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||
|
||||
check_table_not_exists("flight");
|
||||
|
||||
res = query::drop()
|
||||
res = drop()
|
||||
.table("airplane")
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -233,7 +233,7 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute insert record statement", "[query][record]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -248,14 +248,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement", "[query][recor
|
||||
REQUIRE(res->affected_rows == 0);
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({7, "george", 45})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_all(db);
|
||||
|
||||
@@ -276,7 +276,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement", "[query][recor
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key", "[query][record]")
|
||||
{
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("airplane")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -291,7 +291,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||
REQUIRE(res->affected_rows == 0);
|
||||
tables_to_drop.emplace("airplane");
|
||||
|
||||
res = query::create()
|
||||
res = create()
|
||||
.table("flight")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -314,7 +314,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||
};
|
||||
|
||||
for(auto &&values : values_list) {
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("airplane", {"id", "brand", "model"})
|
||||
.values(std::move(values))
|
||||
.execute(db);
|
||||
@@ -322,14 +322,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from("airplane")
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(count->has_value());
|
||||
REQUIRE(*count == 3);
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("flight", {"id", "airplane_id", "pilot_name"})
|
||||
.values({4, 1, "George"})
|
||||
.execute(db);
|
||||
@@ -339,7 +339,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][record]")
|
||||
{
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -354,7 +354,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
||||
REQUIRE(res->affected_rows == 0);
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({7, "george", 45})
|
||||
.execute(db);
|
||||
@@ -362,7 +362,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
res = query::update("person")
|
||||
res = update("person")
|
||||
.set("id", 7)
|
||||
.set("name", "jane")
|
||||
.set("age", 35)
|
||||
@@ -371,7 +371,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_all(db);
|
||||
|
||||
@@ -392,7 +392,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||
{
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -415,7 +415,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||
};
|
||||
|
||||
for(auto &&values : values_list) {
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values(std::move(values))
|
||||
.execute(db);
|
||||
@@ -423,7 +423,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_all(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -435,14 +435,14 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||
}
|
||||
REQUIRE(expected_names.empty());
|
||||
|
||||
auto rec = query::select({"id", "name", "age"})
|
||||
auto rec = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_one(db);
|
||||
REQUIRE(rec.is_ok());
|
||||
REQUIRE(rec->has_value());
|
||||
REQUIRE((*rec)->at(1).str() == "george");
|
||||
|
||||
auto name = query::select({"name"})
|
||||
auto name = select({"name"})
|
||||
.from("person")
|
||||
.fetch_value<std::string>(db);
|
||||
|
||||
@@ -452,7 +452,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query][record]")
|
||||
{
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -475,7 +475,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query
|
||||
};
|
||||
|
||||
for(auto &&values : values_list) {
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values(std::move(values))
|
||||
.execute(db);
|
||||
@@ -483,7 +483,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.order_by("name").asc()
|
||||
.fetch_all(db);
|
||||
@@ -498,7 +498,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order by", "[query][record]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -523,7 +523,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
||||
};
|
||||
|
||||
for(auto &&values : values_list) {
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values(std::move(values))
|
||||
.execute(db);
|
||||
@@ -531,7 +531,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto result = query::select({count("age").as("age_count"), "age"})
|
||||
auto result = select({count("age").as("age_count"), "age"})
|
||||
.from("person")
|
||||
.group_by({"age"})
|
||||
.order_by("age_count").desc()
|
||||
@@ -551,7 +551,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute delete statement", "[query][record]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -566,34 +566,34 @@ TEST_CASE_METHOD(QueryFixture, "Execute delete statement", "[query][record]") {
|
||||
REQUIRE(res->affected_rows == 0);
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({1, "george", 45})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({2, "jane", 45})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from("person")
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
|
||||
REQUIRE(*count == 2);
|
||||
|
||||
res = query::remove()
|
||||
res = remove()
|
||||
.from("person")
|
||||
.where("id"_col == 1)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
count = query::select({count_all()})
|
||||
count = select({count_all()})
|
||||
.from("person")
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
@@ -601,7 +601,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute delete statement", "[query][record]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("quotes")
|
||||
.columns({
|
||||
column("from", basic_type::Varchar, 255),
|
||||
@@ -628,14 +628,14 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||
++i;
|
||||
}
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("quotes", {"from", "to"})
|
||||
.values({"Berlin", "London"})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select({"from", "to"})
|
||||
auto result = select({"from", "to"})
|
||||
.from("quotes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -644,7 +644,7 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||
REQUIRE("Berlin" == (*result)->at("from").str());
|
||||
REQUIRE("London" == (*result)->at("to").str());
|
||||
|
||||
res = query::update("quotes")
|
||||
res = update("quotes")
|
||||
.set("from", "Hamburg")
|
||||
.set("to", "New York")
|
||||
.where("from"_col == "Berlin")
|
||||
@@ -652,7 +652,7 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
result = query::select({"from", "to"})
|
||||
result = select({"from", "to"})
|
||||
.from("quotes")
|
||||
.fetch_one(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -663,7 +663,7 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test create record", "[query][record][create]") {
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -690,7 +690,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create record", "[query][record][create]")
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert record", "[query][record][insert]") {
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -707,14 +707,14 @@ TEST_CASE_METHOD(QueryFixture, "Test insert record", "[query][record][insert]")
|
||||
|
||||
check_table_exists("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({1, "hans", 45})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({"id", "name", "age"})
|
||||
auto row = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -727,7 +727,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert record", "[query][record][insert]")
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]") {
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -744,14 +744,14 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
||||
|
||||
check_table_exists("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({1, "hans", 45})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({"id", "name", "age"})
|
||||
auto row = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -761,7 +761,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
||||
REQUIRE((*row)->at("name").as<std::string>() == "hans");
|
||||
REQUIRE((*row)->at("age").as<unsigned short>() == 45);
|
||||
|
||||
res = query::update("person")
|
||||
res = update("person")
|
||||
.set("name", "jane")
|
||||
.set("age", 47)
|
||||
.where("name"_col == "hans")
|
||||
@@ -769,7 +769,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({"id", "name", "age"})
|
||||
row = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_one(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -782,7 +782,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test prepared record statement", "[query][record][prepared]") {
|
||||
check_table_not_exists("person");
|
||||
auto stmt = query::create()
|
||||
auto stmt = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -812,7 +812,7 @@ TEST_CASE_METHOD(QueryFixture, "Test prepared record statement", "[query][record
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test scalar result", "[query][record][scalar][result]") {
|
||||
check_table_not_exists("person");
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32)
|
||||
@@ -830,7 +830,7 @@ TEST_CASE_METHOD(QueryFixture, "Test scalar result", "[query][record][scalar][re
|
||||
std::vector<uint32_t> ids({ 1,2,3,4 });
|
||||
|
||||
for(auto id : ids) {
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {"id"})
|
||||
.values({id})
|
||||
.execute(db);
|
||||
@@ -838,7 +838,7 @@ TEST_CASE_METHOD(QueryFixture, "Test scalar result", "[query][record][scalar][re
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto stmt = query::select({"id"})
|
||||
auto stmt = select({"id"})
|
||||
.from("person")
|
||||
.order_by("id"_col).asc()
|
||||
.prepare(db);
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") {
|
||||
const auto obj = object_generator::generate<person>(repo.repo(), "persons");
|
||||
auto stmt = query::create()
|
||||
auto stmt = create()
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
@@ -54,7 +54,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
|
||||
|
||||
person george{1, "george", 45, {1,2,3,4}};
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(generator::placeholders<person>())
|
||||
.prepare(db);
|
||||
@@ -65,7 +65,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert statement", "[query][statement][inse
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
auto row = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -85,7 +85,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
|
||||
person george{1, "george", 45, {1,2,3,4}};
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(generator::placeholders<person>())
|
||||
.prepare(db);
|
||||
@@ -96,7 +96,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto row = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
auto row = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -109,7 +109,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
|
||||
george.age = 36;
|
||||
george.image = {5,6,7,8};
|
||||
stmt = query::update(PERSON)
|
||||
stmt = update(PERSON)
|
||||
.set<person>()
|
||||
.where(PERSON.id == _)
|
||||
.prepare(db);
|
||||
@@ -121,7 +121,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update statement", "[query][statement][upda
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
row = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
row = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.fetch_one<person>(db);
|
||||
REQUIRE(row.is_ok());
|
||||
@@ -139,7 +139,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
|
||||
check_table_exists(PERSON.table_name());
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(generator::placeholders<person>())
|
||||
.prepare(db);
|
||||
@@ -160,7 +160,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
auto select_stmt = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
auto select_stmt = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.where(PERSON.name ==_)
|
||||
.prepare(db);
|
||||
@@ -178,7 +178,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete statement", "[query][statement][dele
|
||||
REQUIRE(r->image == peoples[index].image);
|
||||
}
|
||||
|
||||
stmt = query::remove()
|
||||
stmt = remove()
|
||||
.from(PERSON)
|
||||
.where(PERSON.name == _)
|
||||
.prepare(db);
|
||||
@@ -212,7 +212,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
|
||||
|
||||
check_table_exists(PERSON.table_name());
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(generator::placeholders<person>())
|
||||
.prepare(db);
|
||||
@@ -233,7 +233,7 @@ TEST_CASE_METHOD(QueryFixture, "Test reuse prepared statement", "[query][stateme
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
stmt = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
stmt = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt);
|
||||
|
||||
+57
-57
@@ -46,7 +46,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
person george{7, "george", 45};
|
||||
george.image.emplace_back(37);
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(george)
|
||||
.execute(db);
|
||||
@@ -54,7 +54,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
// fetch person as record
|
||||
auto result_record = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
auto result_record = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.where(PERSON.id == 7)
|
||||
.fetch_all(db);
|
||||
@@ -74,7 +74,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[q
|
||||
}
|
||||
|
||||
// fetch person as person
|
||||
auto result_person = query::select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
auto result_person = select({PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.from(PERSON)
|
||||
.where(PERSON.id == 7)
|
||||
.fetch_all<person>(db);
|
||||
@@ -97,7 +97,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert with returning", "[query][insert]
|
||||
person george{7, "george", 45};
|
||||
george.image.emplace_back(37);
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(PERSON, {PERSON.id, PERSON.name, PERSON.age, PERSON.image})
|
||||
.values(george)
|
||||
.returning(PERSON.id)
|
||||
@@ -112,26 +112,26 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert with returning", "[query][insert]
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test sequence", "[query][sequence]") {
|
||||
auto result = query::create()
|
||||
auto result = create()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto next_id = query::select()
|
||||
auto next_id = select()
|
||||
.nextval("person_seq")
|
||||
.fetch_value<uint32_t>(db);
|
||||
|
||||
REQUIRE(next_id.is_ok());
|
||||
REQUIRE(*next_id == 1);
|
||||
|
||||
result = query::drop()
|
||||
result = drop()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
auto res = query::create()
|
||||
auto res = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", matador::utils::basic_type::UInt32),
|
||||
@@ -148,7 +148,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
REQUIRE(db.exists("person"));
|
||||
tables_to_drop.emplace("person");
|
||||
|
||||
res = query::insert()
|
||||
res = insert()
|
||||
.into("person", {{"id", ""}, {"name", ""}, {"color", ""}})
|
||||
.values({7, "george", "green"})
|
||||
.execute(db);
|
||||
@@ -156,7 +156,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
// fetch person as record
|
||||
auto result_record = query::select({"id", "name", "color"})
|
||||
auto result_record = select({"id", "name", "color"})
|
||||
.from("person")
|
||||
.where("id"_col == 7)
|
||||
.fetch_all(db);
|
||||
@@ -192,7 +192,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
};
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(plane)
|
||||
.execute(db);
|
||||
@@ -200,7 +200,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(AIRPLANE)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
@@ -209,14 +209,14 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[query][for
|
||||
|
||||
flight f4711{4, planes.at(1), "hans"};
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(FLIGHT, {FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.values(f4711)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto f = query::select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
auto f = select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.from(FLIGHT)
|
||||
.fetch_one(db);
|
||||
REQUIRE(f.is_ok());
|
||||
@@ -242,7 +242,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
};
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(plane)
|
||||
.execute(db);
|
||||
@@ -250,7 +250,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(AIRPLANE)
|
||||
.fetch_value<int>(db).value();
|
||||
REQUIRE(count == 3);
|
||||
@@ -263,7 +263,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
};
|
||||
|
||||
for (const auto &f: flights) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(FLIGHT, {FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.values(f)
|
||||
.execute(db);
|
||||
@@ -271,7 +271,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto flight_result = query::select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
auto flight_result = select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.from(FLIGHT)
|
||||
.fetch_one(db);
|
||||
REQUIRE(flight_result.is_ok());
|
||||
@@ -283,7 +283,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left"
|
||||
const auto f = FLIGHT.as("f");
|
||||
const auto ap = AIRPLANE.as("ap");
|
||||
|
||||
auto select_result = query::select({f.id, ap.brand, ap.model, f.pilot_name})
|
||||
auto select_result = select({f.id, ap.brand, ap.model, f.pilot_name})
|
||||
.from(f)
|
||||
.join_left(ap)
|
||||
.on(f.airplane_id == ap.id)
|
||||
@@ -323,7 +323,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
};
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(plane)
|
||||
.execute(db);
|
||||
@@ -331,7 +331,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(AIRPLANE)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
@@ -346,7 +346,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
};
|
||||
|
||||
for (const auto &f: flights) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(FLIGHT, {FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.values(f)
|
||||
.execute(db);
|
||||
@@ -354,7 +354,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto flight_result = query::select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
auto flight_result = select({FLIGHT.id, FLIGHT.airplane_id, FLIGHT.pilot_name})
|
||||
.from(FLIGHT)
|
||||
.fetch_one(db);
|
||||
REQUIRE(flight_result.is_ok());
|
||||
@@ -366,7 +366,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
const auto f = FLIGHT.as("f");
|
||||
const auto ap = AIRPLANE.as("ap");
|
||||
|
||||
auto select_result = query::select({f.id, f.airplane_id, ap.brand, ap.model, f.pilot_name})
|
||||
auto select_result = select({f.id, f.airplane_id, ap.brand, ap.model, f.pilot_name})
|
||||
.from(f)
|
||||
.join_left(ap)
|
||||
.on(f.airplane_id == ap.id)
|
||||
@@ -406,7 +406,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
};
|
||||
|
||||
for (const auto &i: ingredients) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(INGREDIENT, {INGREDIENT.id, INGREDIENT.name})
|
||||
.values(i)
|
||||
.execute(db);
|
||||
@@ -421,7 +421,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
};
|
||||
|
||||
for (const auto &r: recipes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(RECIPE, {RECIPE.id, RECIPE.name})
|
||||
.values(r)
|
||||
.execute(db);
|
||||
@@ -441,7 +441,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
};
|
||||
|
||||
for (const auto & [recipe_id, ingredient_id]: recipe_ingredients) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(RECIPE_INGREDIENT, {RECIPE_INGREDIENT.recipe_id, RECIPE_INGREDIENT.ingredient_id})
|
||||
.values({recipe_id, ingredient_id})
|
||||
.execute(db);
|
||||
@@ -454,7 +454,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
const auto ri= RECIPE_INGREDIENT.as("ri");
|
||||
const auto i = INGREDIENT.as("i");
|
||||
|
||||
auto select_result = query::select({ r.id, r.name, ri.ingredient_id})
|
||||
auto select_result = select({ r.id, r.name, ri.ingredient_id})
|
||||
.from(r)
|
||||
.join_left(ri)
|
||||
.on(r.id == ri.recipe_id)
|
||||
@@ -480,7 +480,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
++index;
|
||||
}
|
||||
|
||||
select_result = query::select({r.id, r.name, ri.ingredient_id, i.name})
|
||||
select_result = select({r.id, r.name, ri.ingredient_id, i.name})
|
||||
.from(r)
|
||||
.join_left(ri).on(r.id == ri.recipe_id)
|
||||
.join_left(i).on(ri.ingredient_id == i.id)
|
||||
@@ -507,7 +507,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||
++index;
|
||||
}
|
||||
|
||||
select_result = query::select({r.id, r.name, ri.ingredient_id, i.name})
|
||||
select_result = select({r.id, r.name, ri.ingredient_id, i.name})
|
||||
.from(r)
|
||||
.join_left(ri).on(r.id == ri.recipe_id)
|
||||
.join_left(i).on(ri.ingredient_id == i.id)
|
||||
@@ -546,7 +546,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
};
|
||||
|
||||
for (const auto &sh: shipments) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(SHIPMENT, SHIPMENT)
|
||||
.values(sh)
|
||||
.execute(db);
|
||||
@@ -554,7 +554,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(SHIPMENT)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
@@ -569,7 +569,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
};
|
||||
|
||||
for (const auto &pkg: packages) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(PACKAGE, PACKAGE)
|
||||
.values(pkg)
|
||||
.execute(db);
|
||||
@@ -577,13 +577,13 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
count = query::select({count_all()})
|
||||
count = select({count_all()})
|
||||
.from(PACKAGE)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 5);
|
||||
|
||||
auto pkgs = query::select({PACKAGE.id, PACKAGE.weight, PACKAGE.shipment_id, SHIPMENT.tracking_number})
|
||||
auto pkgs = select({PACKAGE.id, PACKAGE.weight, PACKAGE.shipment_id, SHIPMENT.tracking_number})
|
||||
.from(PACKAGE)
|
||||
.join_left(SHIPMENT)
|
||||
.on( PACKAGE.shipment_id == SHIPMENT.id )
|
||||
@@ -599,7 +599,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
record_printer printer(std::cout);
|
||||
printer.print(*pkgs);
|
||||
|
||||
auto shipment_records = query::select({SHIPMENT.tracking_number, SHIPMENT.id, PACKAGE.weight, PACKAGE.weight})
|
||||
auto shipment_records = select({SHIPMENT.tracking_number, SHIPMENT.id, PACKAGE.weight, PACKAGE.weight})
|
||||
.from(SHIPMENT)
|
||||
.join_left(PACKAGE)
|
||||
.on( SHIPMENT.id == PACKAGE.shipment_id )
|
||||
@@ -609,7 +609,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
|
||||
|
||||
printer.print(*shipment_records);
|
||||
|
||||
auto shipment_result = query::select({SHIPMENT.id, SHIPMENT.tracking_number, PACKAGE.id, PACKAGE.weight, PACKAGE.shipment_id})
|
||||
auto shipment_result = select({SHIPMENT.id, SHIPMENT.tracking_number, PACKAGE.id, PACKAGE.weight, PACKAGE.shipment_id})
|
||||
.from(SHIPMENT)
|
||||
.join_left(PACKAGE)
|
||||
.on( SHIPMENT.id == PACKAGE.shipment_id )
|
||||
@@ -657,7 +657,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "
|
||||
};
|
||||
|
||||
for (const auto &a: authors) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AUTHOR, {AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
|
||||
.values(a)
|
||||
.execute(db);
|
||||
@@ -665,14 +665,14 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(AUTHOR)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 2);
|
||||
|
||||
for (const auto &b: books) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(BOOK, {BOOK.id, BOOK.title, BOOK.author_id, BOOK.published_in})
|
||||
.values(b)
|
||||
.execute(db);
|
||||
@@ -680,13 +680,13 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
count = query::select({count_all()})
|
||||
count = select({count_all()})
|
||||
.from(BOOK)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 10);
|
||||
|
||||
auto author_result = query::select({AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
|
||||
auto author_result = select({AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
|
||||
.from(AUTHOR)
|
||||
.order_by(AUTHOR.id).asc()
|
||||
.fetch_all<author>(db);
|
||||
@@ -734,7 +734,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation",
|
||||
};
|
||||
|
||||
for (const auto &dep: deps) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(DEPARTMENT, {DEPARTMENT.id, DEPARTMENT.name})
|
||||
.values(dep)
|
||||
.execute(db);
|
||||
@@ -742,14 +742,14 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation",
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(DEPARTMENT)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 2);
|
||||
|
||||
for (const auto &emp: emps) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(EMPLOYEE, {EMPLOYEE.id, EMPLOYEE.first_name, EMPLOYEE.last_name, EMPLOYEE.dep_id})
|
||||
.values(emp)
|
||||
.execute(db);
|
||||
@@ -757,13 +757,13 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation",
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
count = query::select({count_all()})
|
||||
count = select({count_all()})
|
||||
.from(EMPLOYEE)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 5);
|
||||
|
||||
auto emps_result = query::select({EMPLOYEE.id, EMPLOYEE.first_name, EMPLOYEE.last_name, EMPLOYEE.dep_id})
|
||||
auto emps_result = select({EMPLOYEE.id, EMPLOYEE.first_name, EMPLOYEE.last_name, EMPLOYEE.dep_id})
|
||||
.from(EMPLOYEE)
|
||||
.order_by(EMPLOYEE.id).asc()
|
||||
.fetch_all<employee>(db);
|
||||
@@ -805,7 +805,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager belongs to relation"
|
||||
};
|
||||
|
||||
for (const auto &a: authors) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AUTHOR, {AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
|
||||
.values(a)
|
||||
.execute(db);
|
||||
@@ -813,14 +813,14 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager belongs to relation"
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto count = query::select({count_all()})
|
||||
auto count = select({count_all()})
|
||||
.from(AUTHOR)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 2);
|
||||
|
||||
for (const auto &b: books) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(BOOK, {BOOK.id, BOOK.title, BOOK.author_id, BOOK.published_in})
|
||||
.values(b)
|
||||
.execute(db);
|
||||
@@ -828,13 +828,13 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager belongs to relation"
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
count = query::select({count_all()})
|
||||
count = select({count_all()})
|
||||
.from(BOOK)
|
||||
.fetch_value<int>(db);
|
||||
REQUIRE(count.is_ok());
|
||||
REQUIRE(*count == 10);
|
||||
|
||||
auto books_result = query::select({BOOK.id, BOOK.title, AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished, BOOK.published_in})
|
||||
auto books_result = select({BOOK.id, BOOK.title, AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished, BOOK.published_in})
|
||||
.from(BOOK)
|
||||
.join_left(AUTHOR)
|
||||
.on(BOOK.author_id == AUTHOR.id)
|
||||
@@ -881,7 +881,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
};
|
||||
|
||||
for (const auto &i: ingredients) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(INGREDIENT, {INGREDIENT.id, INGREDIENT.name})
|
||||
.values(i)
|
||||
.execute(db);
|
||||
@@ -896,7 +896,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
};
|
||||
|
||||
for (const auto &r: recipes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(RECIPE, {RECIPE.id, RECIPE.name})
|
||||
.values(r)
|
||||
.execute(db);
|
||||
@@ -916,7 +916,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
};
|
||||
|
||||
for (const auto & [recipe_id, ingredient_id]: recipe_ingredients) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(RECIPE_INGREDIENT, {RECIPE_INGREDIENT.recipe_id, RECIPE_INGREDIENT.ingredient_id})
|
||||
.values({recipe_id, ingredient_id})
|
||||
.execute(db);
|
||||
@@ -928,7 +928,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
const auto ri= RECIPE_INGREDIENT.as("ri");
|
||||
const auto i = INGREDIENT.as("i");
|
||||
|
||||
auto recipes_result = query::select({r.id, r.name })
|
||||
auto recipes_result = select({r.id, r.name })
|
||||
.from(r)
|
||||
.order_by({r.id}).asc()
|
||||
.fetch_all<recipe>(db);
|
||||
@@ -941,7 +941,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
}
|
||||
}
|
||||
|
||||
auto ingredients_result = query::select({i.id, i.name, ri.recipe_id, r.name})
|
||||
auto ingredients_result = select({i.id, i.name, ri.recipe_id, r.name})
|
||||
.from(i)
|
||||
.join_left(ri).on(i.id == ri.ingredient_id)
|
||||
.join_left(r).on(ri.recipe_id == r.id)
|
||||
|
||||
@@ -37,7 +37,7 @@ void SequenceFixture::check_sequence_not_exists(const std::string& sequence_name
|
||||
void SequenceFixture::drop_sequence_if_exists(const std::string& sequence_name) const {
|
||||
const auto result = db.sequence_exists(sequence_name).and_then([&sequence_name, this](const bool exists) {
|
||||
if (exists) {
|
||||
auto res = query::query::drop()
|
||||
auto res = query::drop()
|
||||
.sequence(sequence_name)
|
||||
.execute(db);
|
||||
REQUIRE(res);
|
||||
|
||||
@@ -9,35 +9,35 @@ using namespace matador::query;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(SequenceFixture, "test create and drop sequence", "[sequence][create][drop]") {
|
||||
auto result = query::create()
|
||||
auto result = create()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
sequences_to_drop.emplace("person_seq");
|
||||
|
||||
auto next_id = query::select()
|
||||
auto next_id = select()
|
||||
.nextval("person_seq")
|
||||
.fetch_value<uint32_t>(db);
|
||||
|
||||
REQUIRE(next_id.is_ok());
|
||||
REQUIRE(*next_id == 1);
|
||||
|
||||
auto curr_id = query::select()
|
||||
auto curr_id = select()
|
||||
.currval("person_seq")
|
||||
.fetch_value<uint32_t>(db);
|
||||
|
||||
REQUIRE(curr_id.is_ok());
|
||||
REQUIRE(*curr_id == 1);
|
||||
|
||||
result = query::drop()
|
||||
result = drop()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SequenceFixture, "Test nextval and currval through sequence pk generator", "[sequence][nextval][currval]") {
|
||||
auto result = query::create()
|
||||
auto result = create()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -54,7 +54,7 @@ TEST_CASE_METHOD(SequenceFixture, "Test nextval and currval through sequence pk
|
||||
REQUIRE(pk_result.is_ok());
|
||||
REQUIRE(*pk_result == 1);
|
||||
|
||||
result = query::drop()
|
||||
result = drop()
|
||||
.sequence("person_seq")
|
||||
.execute(db);
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
@@ -40,7 +40,7 @@ protected:
|
||||
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
|
||||
using namespace matador::utils;
|
||||
SECTION("Insert with prepared statement and placeholder") {
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(generator::placeholders<airplane>())
|
||||
.prepare(db);
|
||||
@@ -53,7 +53,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
auto result = query::select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
auto result = select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.from(AIRPLANE)
|
||||
.fetch_all<airplane>(db);
|
||||
|
||||
@@ -68,7 +68,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
|
||||
SECTION("Select with prepared statement") {
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(plane)
|
||||
.execute(db);
|
||||
@@ -76,7 +76,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
}
|
||||
|
||||
auto stmt = query::select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
auto stmt = select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.from(AIRPLANE)
|
||||
.where(AIRPLANE.brand == _)
|
||||
.prepare(db);
|
||||
|
||||
@@ -12,7 +12,7 @@ TableSequenceFixture::TableSequenceFixture()
|
||||
: db(connection::dns) {
|
||||
REQUIRE(db.open());
|
||||
|
||||
REQUIRE(query::query::create()
|
||||
REQUIRE(query::create()
|
||||
.table(sequence_table_name)
|
||||
.columns({
|
||||
query::column("name", utils::basic_type::Varchar, 255),
|
||||
@@ -22,7 +22,7 @@ TableSequenceFixture::TableSequenceFixture()
|
||||
}
|
||||
|
||||
TableSequenceFixture::~TableSequenceFixture() {
|
||||
REQUIRE(query::query::drop()
|
||||
REQUIRE(query::drop()
|
||||
.table(sequence_table_name)
|
||||
.execute(db));
|
||||
REQUIRE(db.close());
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace matador::test;
|
||||
|
||||
TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[table_sequence][create][drop]") {
|
||||
const auto next_id_col = "next_id"_col;
|
||||
auto result = query::query::insert()
|
||||
auto result = insert()
|
||||
.into(sequence_table_name, { "name", next_id_col})
|
||||
.values({ "test_seq", 1 })
|
||||
.execute(db);
|
||||
@@ -21,7 +21,7 @@ TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[
|
||||
REQUIRE(result->affected_rows == 1);
|
||||
|
||||
table_column exp(next_id_col - 1);
|
||||
auto id_result = query::query::update(sequence_table_name)
|
||||
auto id_result = update(sequence_table_name)
|
||||
.set(next_id_col, next_id_col + 1)
|
||||
.where("name"_col == "test_seq")
|
||||
.returning((next_id_col - 1).as("id"))
|
||||
@@ -31,7 +31,7 @@ TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[
|
||||
REQUIRE(id_result->has_value());
|
||||
REQUIRE(id_result->value() == 1);
|
||||
|
||||
id_result = query::query::select({next_id_col})
|
||||
id_result = select({next_id_col})
|
||||
.from(sequence_table_name)
|
||||
.where("name"_col == "test_seq")
|
||||
.fetch_value<int64_t>(db);
|
||||
@@ -42,7 +42,7 @@ TEST_CASE_METHOD(TableSequenceFixture, "test create and drop table sequence", "[
|
||||
|
||||
TEST_CASE_METHOD(TableSequenceFixture, "Test nextval and currval through table sequence pk generator", "[table_sequence][nextval][currval]" ) {
|
||||
const auto next_id_col = "next_id"_col;
|
||||
auto result = query::query::insert()
|
||||
auto result = insert()
|
||||
.into(sequence_table_name, { "name", next_id_col})
|
||||
.values({ "test_seq", 1 })
|
||||
.execute(db);
|
||||
|
||||
@@ -31,14 +31,14 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
|
||||
SECTION("Insert and select with direct execution") {
|
||||
location loc{1, "center", {1, 2, 3}, Color::Black};
|
||||
|
||||
auto res = query::insert()
|
||||
auto res = insert()
|
||||
.into("location", generator::columns<location>(repo))
|
||||
.values(loc)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select(generator::columns<location>(repo))
|
||||
auto result = select(generator::columns<location>(repo))
|
||||
.from("location")
|
||||
.fetch_one<location>(db);
|
||||
|
||||
@@ -53,7 +53,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
|
||||
SECTION("Insert and select with prepared statement") {
|
||||
location loc{1, "center", {1, 2, 3}, Color::Black};
|
||||
|
||||
auto stmt = query::insert()
|
||||
auto stmt = insert()
|
||||
.into("location", generator::columns<location>(repo))
|
||||
.values(generator::placeholders<location>())
|
||||
.prepare(db);
|
||||
@@ -63,7 +63,7 @@ TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with typ
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res->affected_rows == 1);
|
||||
|
||||
auto result = query::select(generator::columns<location>(repo))
|
||||
auto result = select(generator::columns<location>(repo))
|
||||
.from("location")
|
||||
.fetch_one<location>(db);
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ TEST_CASE_METHOD(CriteriaFixture, "Test in query criteria", "[criteria][in query
|
||||
query_context sub_ctx;
|
||||
sub_ctx.sql = R"(SELECT "name" FROM "test")";
|
||||
|
||||
auto q = query::select({name_col}).from("test");
|
||||
auto q = select({name_col}).from("test");
|
||||
|
||||
auto clause = age_col != 7 && in(name_col, std::move(q));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ using namespace matador::query;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test alter table sql statement", "[query][alter][table]") {
|
||||
auto result = query::alter()
|
||||
auto result = alter()
|
||||
.table("employees")
|
||||
.add_constraint("FK_employees_dep_id")
|
||||
.foreign_key("dep_id"_col)
|
||||
@@ -27,7 +27,7 @@ TEST_CASE_METHOD(QueryFixture, "Test alter table sql statement", "[query][alter]
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(ALTER TABLE "employees" ADD CONSTRAINT FK_employees_dep_id FOREIGN KEY ("dep_id") REFERENCES departments ("id"))");
|
||||
result = query::alter()
|
||||
result = alter()
|
||||
.table("employees")
|
||||
.drop_constraint("FK_employees_dep_id")
|
||||
.str(*db);
|
||||
@@ -36,7 +36,7 @@ TEST_CASE_METHOD(QueryFixture, "Test alter table sql statement", "[query][alter]
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query]") {
|
||||
auto result = query::create()
|
||||
auto result = create()
|
||||
.table({"person"})
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -50,7 +50,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||
|
||||
REQUIRE(result == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL, "name" VARCHAR(255) NOT NULL, "age" INTEGER NOT NULL, CONSTRAINT PK_person PRIMARY KEY (id)))##");
|
||||
|
||||
result = query::create()
|
||||
result = create()
|
||||
.table({"person"})
|
||||
.columns({
|
||||
column("id", basic_type::UInt32).primary_key().identity(),
|
||||
@@ -61,7 +61,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||
|
||||
REQUIRE(result == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL AUTO INCREMENT PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "age" INTEGER NOT NULL))##");
|
||||
|
||||
auto ctx = query::create()
|
||||
auto ctx = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -79,7 +79,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test drop table sql statement string", "[query]") {
|
||||
const auto result = query::drop()
|
||||
const auto result = drop()
|
||||
.table("person")
|
||||
.str(*db);
|
||||
|
||||
@@ -87,7 +87,7 @@ TEST_CASE_METHOD(QueryFixture, "Test drop table sql statement string", "[query]"
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select all columns with asterisk", "[query][select][asterisk]") {
|
||||
const auto result = query::select()
|
||||
const auto result = select()
|
||||
.from("person")
|
||||
.str(*db);
|
||||
|
||||
@@ -95,7 +95,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select all columns with asterisk", "[query]
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string", "[query]") {
|
||||
const auto result = query::select({"id", "name", "age"})
|
||||
const auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.str(*db);
|
||||
|
||||
@@ -103,7 +103,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string", "[query]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert sql statement string", "[query]") {
|
||||
const auto result = query::insert()
|
||||
const auto result = insert()
|
||||
.into("person", {
|
||||
"id", "name", "age"
|
||||
})
|
||||
@@ -114,7 +114,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement string", "[query]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||
auto result = query::update("person")
|
||||
auto result = update("person")
|
||||
.set("id", 7U)
|
||||
.set("name", "george")
|
||||
.set("age", 65U)
|
||||
@@ -122,7 +122,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||
|
||||
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
|
||||
|
||||
result = query::update("person")
|
||||
result = update("person")
|
||||
.set("id", 7U)
|
||||
.set("name", "george")
|
||||
.set("age", 65U)
|
||||
@@ -136,7 +136,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][update][returning]") {
|
||||
const auto result = query::update("person")
|
||||
const auto result = update("person")
|
||||
.set("id", 7U)
|
||||
.set("name", "george")
|
||||
.set("age", 65U)
|
||||
@@ -148,7 +148,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][updat
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][update][limit]") {
|
||||
const auto result = query::update("person")
|
||||
const auto result = update("person")
|
||||
.set("id", 7U)
|
||||
.set("name", "george")
|
||||
.set("age", 65U)
|
||||
@@ -161,13 +161,13 @@ TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][updat
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test delete sql statement string", "[query]") {
|
||||
const auto result = query::remove().from("person").str(*db);
|
||||
const auto result = remove().from("person").str(*db);
|
||||
|
||||
REQUIRE(result == R"(DELETE FROM "person")");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test delete limit sql statement", "[query][delete][limit]") {
|
||||
const auto result = query::remove()
|
||||
const auto result = remove()
|
||||
.from("person")
|
||||
.where("name"_col == "george")
|
||||
.order_by("id"_col).asc()
|
||||
@@ -178,14 +178,14 @@ TEST_CASE_METHOD(QueryFixture, "Test delete limit sql statement", "[query][delet
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with where clause", "[query]") {
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == 8 && "age"_col > 50)
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = 8 AND "age" > 50))");
|
||||
|
||||
result = query::select({"id", "name", "age"})
|
||||
result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.where("id"_col == _ && "age"_col > 50)
|
||||
.str(*db);
|
||||
@@ -194,14 +194,14 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with where clau
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with placeholder", "[query]") {
|
||||
auto result = query::insert()
|
||||
auto result = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({_, _, _})
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (?, ?, ?))");
|
||||
|
||||
result = query::insert()
|
||||
result = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({9, "george", _})
|
||||
.str(*db);
|
||||
@@ -210,7 +210,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with placeholder", "[q
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with returning", "[query][insert][returning]") {
|
||||
const auto result = query::insert()
|
||||
const auto result = insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({9, "george", _})
|
||||
.returning("id"_col, "name"_col, "age"_col)
|
||||
@@ -220,7 +220,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with returning", "[que
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with order by", "[query]") {
|
||||
const auto result = query::select({"id", "name", "age"})
|
||||
const auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.order_by("name"_col).asc()
|
||||
.str(*db);
|
||||
@@ -229,7 +229,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with order by",
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with group by", "[query]") {
|
||||
const auto result = query::select({"id", "name", "age"})
|
||||
const auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.group_by("age"_col)
|
||||
.str(*db);
|
||||
@@ -238,7 +238,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with group by",
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with offset and limit", "[query]") {
|
||||
const auto result = query::select({"id", "name", "age"})
|
||||
const auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.order_by("id"_col).asc()
|
||||
.limit(20)
|
||||
@@ -249,7 +249,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with offset and
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "[query][blob]") {
|
||||
auto result = query::create()
|
||||
auto result = create()
|
||||
.table("person")
|
||||
.columns({
|
||||
column("id", basic_type::UInt32),
|
||||
@@ -263,14 +263,14 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
|
||||
|
||||
REQUIRE(result == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL, "name" VARCHAR(255) NOT NULL, "data" BLOB NOT NULL, CONSTRAINT PK_person PRIMARY KEY (id)))##");
|
||||
|
||||
result = query::insert()
|
||||
result = insert()
|
||||
.into("person", {"id", "name", "data"})
|
||||
.values({7U, "george", blob_type_t{1, 'A', 3, 4}})
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "data") VALUES (7, 'george', X'01410304'))");
|
||||
|
||||
result = query::select({"id", "name", "data"})
|
||||
result = select({"id", "name", "data"})
|
||||
.from("person")
|
||||
.str(*db);
|
||||
|
||||
@@ -282,7 +282,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select statement with join_left", "[query][
|
||||
const auto f = table("flight").as("f");
|
||||
const table_column col1 = {&f, "airplane_id"};
|
||||
const table_column col2 = {&ap, "id"};
|
||||
const auto result = query::select({"f.id", "ap.brand", "f.pilot_name"})
|
||||
const auto result = select({"f.id", "ap.brand", "f.pilot_name"})
|
||||
.from(table{"flight"}.as("f"))
|
||||
.join_left(table{"airplane"}.as("ap"))
|
||||
.on(col1 == col2)
|
||||
@@ -299,7 +299,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select statement with join_left", "[query][
|
||||
// scm.attach<book>("books");
|
||||
//
|
||||
//
|
||||
// const auto result = query::select<author>(scm)
|
||||
// const auto result = select<author>(scm)
|
||||
// .from("authors"_tab.as("T01"))
|
||||
// .str(*db);
|
||||
//
|
||||
|
||||
@@ -8,7 +8,7 @@ using namespace matador::test;
|
||||
using namespace matador::query;
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test simple query", "[query][fetch]") {
|
||||
auto result = query::select({"id", "name", "age"})
|
||||
auto result = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_all(*db);
|
||||
|
||||
@@ -18,7 +18,7 @@ TEST_CASE_METHOD(QueryFixture, "Test simple query", "[query][fetch]") {
|
||||
REQUIRE(row.size() == 3);
|
||||
}
|
||||
|
||||
auto single = query::select({"id", "name", "age"})
|
||||
auto single = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_one(*db);
|
||||
|
||||
@@ -26,7 +26,7 @@ TEST_CASE_METHOD(QueryFixture, "Test simple query", "[query][fetch]") {
|
||||
REQUIRE(single.value().has_value());
|
||||
REQUIRE(single.value().value().size() == 3);
|
||||
|
||||
auto val = query::select({"id", "name", "age"})
|
||||
auto val = select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_value<int>(*db);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user