small fixes and renames

This commit is contained in:
2026-05-23 20:48:21 +02:00
parent cc0bcbeb61
commit 141d798a41
10 changed files with 73 additions and 76 deletions
+27 -27
View File
@@ -24,13 +24,13 @@ TEST_CASE_METHOD(QueryFixture, "Test alter table sql statement", "[query][alter]
.add_constraint("FK_employees_dep_id")
.foreign_key("dep_id"_col)
.references("departments", {"id"_col})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(ALTER TABLE "employees" ADD CONSTRAINT FK_employees_dep_id FOREIGN KEY ("dep_id") REFERENCES departments ("id"))");
result = alter()
.table("employees")
.drop_constraint("FK_employees_dep_id")
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(ALTER TABLE "employees" DROP CONSTRAINT FK_employees_dep_id)");
}
@@ -46,7 +46,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
.constraints({
constraint("PK_person").primary_key({"id"})
})
.str(*db);
.str(db->dialect());
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)))##");
@@ -57,7 +57,7 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
column("name", basic_type::Varchar, 255),
column("age", basic_type::UInt16)
})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL AUTO INCREMENT PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "age" INTEGER NOT NULL))##");
@@ -81,7 +81,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 = drop()
.table("person")
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(DROP TABLE "person")");
}
@@ -89,7 +89,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 = select()
.from("person")
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT * FROM "person")");
}
@@ -97,7 +97,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 = select({"id", "name", "age"})
.from("person")
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person")");
}
@@ -108,7 +108,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement string", "[query]") {
"id", "name", "age"
})
.values({7U, "george", 65U})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (7, 'george', 65))");
}
@@ -118,7 +118,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
.set("id", 7U)
.set("name", "george")
.set("age", 65U)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
@@ -130,7 +130,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
.order_by("id").asc()
.limit(3)
.offset(2)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65 WHERE "id" > 9 ORDER BY "id" ASC LIMIT 3 OFFSET 2)");
}
@@ -142,7 +142,7 @@ TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][updat
.set("age", 65U)
.where("name"_col == "george")
.returning("id"_col, "name"_col, "age"_col)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65 WHERE "name" = 'george' RETURNING "id", "name", "age")");
}
@@ -155,13 +155,13 @@ TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][updat
.where("name"_col == "george")
.order_by("id"_col).asc()
.limit(2)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65 WHERE "name" = 'george' ORDER BY "id" ASC LIMIT 2)");
}
TEST_CASE_METHOD(QueryFixture, "Test delete sql statement string", "[query]") {
const auto result = remove().from("person").str(*db);
const auto result = remove().from("person").str(db->dialect());
REQUIRE(result == R"(DELETE FROM "person")");
}
@@ -172,7 +172,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete limit sql statement", "[query][delet
.where("name"_col == "george")
.order_by("id"_col).asc()
.limit(2)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(DELETE FROM "person" WHERE "name" = 'george' ORDER BY "id" ASC LIMIT 2)");
}
@@ -181,14 +181,14 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with where clau
auto result = select({"id", "name", "age"})
.from("person")
.where("id"_col == 8 && "age"_col > 50)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = 8 AND "age" > 50))");
result = select({"id", "name", "age"})
.from("person")
.where("id"_col == _ && "age"_col > 50)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = ? AND "age" > 50))");
}
@@ -197,14 +197,14 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with placeholder", "[q
auto result = insert()
.into("person", {"id", "name", "age"})
.values({_, _, _})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (?, ?, ?))");
result = insert()
.into("person", {"id", "name", "age"})
.values({9, "george", _})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (9, 'george', ?))");
}
@@ -214,7 +214,7 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with returning", "[que
.into("person", {"id", "name", "age"})
.values({9, "george", _})
.returning("id"_col, "name"_col, "age"_col)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (9, 'george', ?) RETURNING "id", "name", "age")");
}
@@ -223,7 +223,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with order by",
const auto result = select({"id", "name", "age"})
.from("person")
.order_by("name"_col).asc()
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" ORDER BY "name" ASC)");
}
@@ -232,7 +232,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with group by",
const auto result = select({"id", "name", "age"})
.from("person")
.group_by("age"_col)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" GROUP BY "age")");
}
@@ -243,7 +243,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with offset and
.order_by("id"_col).asc()
.limit(20)
.offset(10)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "age" FROM "person" ORDER BY "id" ASC LIMIT 20 OFFSET 10)");
}
@@ -259,20 +259,20 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
.constraints({
constraint("PK_person").primary_key({"id"})
})
.str(*db);
.str(db->dialect());
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 = insert()
.into("person", {"id", "name", "data"})
.values({7U, "george", blob_type_t{1, 'A', 3, 4}})
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "data") VALUES (7, 'george', X'01410304'))");
result = select({"id", "name", "data"})
.from("person")
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "id", "name", "data" FROM "person")");
}
@@ -286,7 +286,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select statement with join_left", "[query][
.from(table{"flight"}.as("f"))
.join_left(table{"airplane"}.as("ap"))
.on(col1 == col2)
.str(*db);
.str(db->dialect());
REQUIRE(result == R"(SELECT "f"."id", "ap"."brand", "f"."pilot_name" FROM "flight" "f" LEFT JOIN "airplane" "ap" ON "f"."airplane_id" = "ap"."id")");
}
@@ -301,7 +301,7 @@ TEST_CASE_METHOD(QueryFixture, "Test select statement with join_left", "[query][
//
// const auto result = select<author>(scm)
// .from("authors"_tab.as("T01"))
// .str(*db);
// .str(db->dialect());
//
// const auto expected_sql = R"(SELECT "T01"."id", "T01"."first_name", "T01"."last_name", "T01"."date_of_birth", "T01"."year_of_birth", "T01"."distinguished" FROM "authors" "T01")";
//
+9 -9
View File
@@ -53,7 +53,7 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
auto q = eqb.build<flight>(*col == _);
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t02"."id", "t02"."brand", "t02"."model", "t01"."pilot_name" FROM "flights" "t01" LEFT JOIN "airplanes" "t02" ON "t01"."airplane_id" = "t02"."id" WHERE "t01"."id" = ? ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
@@ -111,7 +111,7 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
auto q = eqb.build<book>(*col == _);
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."title", "t02"."id", "t02"."first_name", "t02"."last_name", "t02"."date_of_birth", "t02"."year_of_birth", "t02"."distinguished", "t01"."published_in" FROM "books" "t01" LEFT JOIN "authors" "t02" ON "t01"."author_id" = "t02"."id" WHERE "t01"."id" = ? ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
@@ -188,7 +188,7 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
auto q = eqb.build<order>(*col == _);
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."order_id", "t01"."order_date", "t01"."required_date", "t01"."shipped_date", "t01"."ship_via", "t01"."freight", "t01"."ship_name", "t01"."ship_address", "t01"."ship_city", "t01"."ship_region", "t01"."ship_postal_code", "t01"."ship_country", "t02"."order_details_id", "t02"."order_id" FROM "orders" "t01" LEFT JOIN "order_details" "t02" ON "t01"."order_id" = "t02"."order_id" WHERE "t01"."order_id" = ? ORDER BY "t01"."order_id" ASC)";
REQUIRE(expected_sql == sql);
@@ -256,7 +256,7 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
auto q = eqb.build<ingredient>(*col == _);
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t03"."id", "t03"."name" FROM "ingredients" "t01" LEFT JOIN "recipe_ingredients" "t02" ON "t01"."id" = "t02"."ingredient_id" LEFT JOIN "recipes" "t03" ON "t02"."recipe_id" = "t03"."id" WHERE "t01"."id" = ? ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
@@ -315,7 +315,7 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
auto q = eqb.build<course>(*col == _);
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."title", "t03"."id", "t03"."name" FROM "courses" "t01" LEFT JOIN "student_courses" "t02" ON "t01"."id" = "t02"."course_id" LEFT JOIN "students" "t03" ON "t02"."student_id" = "t03"."id" WHERE "t01"."id" = ? ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
@@ -369,11 +369,11 @@ TEST_CASE("Test eager relationship", "[query][entity][builder]") {
auto q = eqb.build<department>();
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t02"."id", "t02"."first_name", "t02"."last_name", "t02"."dep_id" FROM "departments" "t01" LEFT JOIN "employees" "t02" ON "t01"."id" = "t02"."dep_id" ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
const auto& data = eqb.query_data();
// const auto& data = eqb.query_data();
// auto ctx = query::select(data.columns)
@@ -401,7 +401,7 @@ TEST_CASE("Test has one lazy relationship", "[query][entity][builder][has_one][l
auto q = eqb.build<user>();
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t01"."password" FROM "users" "t01" ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);
@@ -421,7 +421,7 @@ TEST_CASE("Test has one eager relationship", "[query][entity][builder][has_one][
auto q = eqb.build<country>();
REQUIRE(q.is_ok());
const auto sql = q->str(db);
const auto sql = q->str(db.dialect());
const std::string expected_sql = R"(SELECT "t01"."id", "t01"."name", "t02"."id", "t02"."name", "t02"."country_id" FROM "countries" "t01" LEFT JOIN "capitals" "t02" ON "t01"."id" = "t02"."country_id" ORDER BY "t01"."id" ASC)";
REQUIRE(expected_sql == sql);