removed class query and moved their static methods to simple functions
This commit is contained in:
@@ -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