query builder progress

This commit is contained in:
Sascha Kühl
2025-12-03 16:18:03 +01:00
parent bfbbd4c589
commit 19eb54df8d
11 changed files with 360 additions and 192 deletions
+57 -39
View File
@@ -26,28 +26,30 @@ using namespace matador::object;
using namespace matador::query;
TEST_CASE_METHOD( QueryFixture, "Insert and select basic datatypes", "[query][datatypes]" ) {
REQUIRE(repo.attach<types>("types"));
auto res = query::create()
.table<types>("types", repo)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
tables_to_drop.emplace("types");
float float_value = 2.44557f;
double double_value = 11111.23433345;
int8_t cval = 'c';
short sval = (std::numeric_limits<short>::min)();
int ival = (std::numeric_limits<int>::min)();
int64_t llval = (std::numeric_limits<long long>::max)();
unsigned char ucval = (std::numeric_limits<unsigned char>::max)();
unsigned short usval = (std::numeric_limits<unsigned short>::max)();
unsigned int uival = (std::numeric_limits<unsigned int>::max)();
uint64_t ullval = (std::numeric_limits<unsigned long long>::max)();
if (db.type() == "sqlite" || db.type() == "postgres") {
ullval = (std::numeric_limits<long long>::max)();
}
bool bval = true;
REQUIRE(repo.attach<types>("types"));
auto obj = object_generator::generate<types>(repo, "types");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
.constraints(obj->constraints())
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
tables_to_drop.emplace("types");
float float_value = 2.44557f;
double double_value = 11111.23433345;
int8_t cval = 'c';
short sval = (std::numeric_limits<short>::min)();
int ival = (std::numeric_limits<int>::min)();
int64_t llval = (std::numeric_limits<long long>::max)();
unsigned char ucval = (std::numeric_limits<unsigned char>::max)();
unsigned short usval = (std::numeric_limits<unsigned short>::max)();
unsigned int uival = (std::numeric_limits<unsigned int>::max)();
uint64_t ullval = (std::numeric_limits<unsigned long long>::max)();
if (db.type() == "sqlite" || db.type() == "postgres") {
ullval = (std::numeric_limits<long long>::max)();
}
bool bval = true;
const char *cstr("Armer schwarzer Kater");
std::string varcharval("hallo welt");
std::string strval = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
@@ -111,9 +113,10 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
using namespace matador::sql;
auto res = query::create()
.table("quotes", {
make_column<std::string>("from", 255),
make_column<std::string>("to", 255)
.table("quotes")
.columns({
attribute("from", matador::utils::basic_type::type_varchar, 255),
attribute("to", matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());
@@ -126,9 +129,11 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
const auto columns = db.describe("quotes");
REQUIRE(columns.is_ok());
size_t i = 0;
for (const auto &col : *columns) {
REQUIRE(col.name() == column_names[col.index()]);
REQUIRE(col.type() == types[col.index()]);
REQUIRE(col.name() == column_names[i]);
REQUIRE(col.type() == types[i]);
++i;
}
res = query::insert()
@@ -183,8 +188,9 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
for (const auto &name : column_names) {
auto res = query::create()
.table("quotes", {
make_column<std::string>(name, 255),
.table("quotes")
.columns({
attribute(name, matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());
@@ -210,8 +216,9 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
using namespace matador::sql;
auto res = query::create()
.table("escapes", {
make_column<std::string>("name", 255),
.table("escapes")
.columns({
attribute("name", matador::utils::basic_type::type_varchar, 255)
})
.execute(db);
REQUIRE(res.is_ok());
@@ -280,8 +287,11 @@ TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]"
using namespace matador::sql;
REQUIRE(repo.attach<types>("types"));
const auto res = query::create()
.table<types>("types", repo)
auto obj = object_generator::generate<types>(repo, "types");
auto res = query::create()
.table(obj->name())
.columns(obj->attributes())
.constraints(obj->constraints())
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@@ -321,9 +331,11 @@ TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]"
};
const auto &cols = columns.value();
size_t i = 0;
for (const auto &col : cols) {
REQUIRE(col.name() == column_names[col.index()]);
REQUIRE(type_check[col.index()](col));
REQUIRE(col.name() == column_names[i]);
REQUIRE(type_check[i](col));
++i;
}
}
@@ -339,8 +351,8 @@ namespace matador::test::temporary {
struct pk {
template<class Operator>
void process(Operator &op) {
matador::access::primary_key(op, "id", id);
matador::access::attribute(op, "name", name, 255);
access::primary_key(op, "id", id);
access::attribute(op, "name", name, 255);
}
uint32_t id{};
@@ -353,8 +365,11 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key", "[query][primary key]") {
using namespace matador::sql;
REQUIRE(repo.attach<pk>("pk"));
auto obj = object_generator::generate<pk>(repo, "pk");
auto res = query::create()
.table<pk>("pk", repo)
.table(obj->name())
.columns(obj->attributes())
.constraints(obj->constraints())
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);
@@ -382,8 +397,11 @@ TEST_CASE_METHOD(QueryFixture, "Test primary key prepared", "[query][primary key
using namespace matador::sql;
REQUIRE(repo.attach<pk>("pk"));
auto obj = object_generator::generate<pk>(repo, "pk");
auto res = query::create()
.table<pk>("pk", repo)
.table(obj->name())
.columns(obj->attributes())
.constraints(obj->constraints())
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 0);