query builder progress
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
#include <matador/query/query.hpp>
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
#include "matador/utils/placeholder.hpp"
|
||||
@@ -37,21 +35,32 @@ 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()
|
||||
.table({"person"}, {
|
||||
make_pk_column<uint32_t>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<unsigned short>("age")
|
||||
}).str(*db);
|
||||
.table({"person"})
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"})
|
||||
})
|
||||
.str(*db);
|
||||
|
||||
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)))##");
|
||||
|
||||
auto ctx = query::create()
|
||||
.table("person", {
|
||||
make_pk_column<uint32_t>("id"),
|
||||
make_column<std::string>("name", {255, constraints::Unique}, null_option_type::NOT_NULL),
|
||||
make_column<unsigned short>("age"),
|
||||
make_fk_column<uint32_t>("address", "address", "id")
|
||||
}).compile(*db);
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("age", basic_type::type_uint16),
|
||||
attribute("address", basic_type::type_uint32)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"}),
|
||||
constraint("FK_person_address").foreign_key({"address"}).references("address", {"id"})
|
||||
})
|
||||
.compile(*db);
|
||||
|
||||
REQUIRE(ctx.sql == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL, "name" VARCHAR(255) NOT NULL UNIQUE, "age" INTEGER NOT NULL, "address" BIGINT NOT NULL, CONSTRAINT PK_person PRIMARY KEY (id)))##");
|
||||
REQUIRE(ctx.additional_commands.size() == 1);
|
||||
@@ -210,10 +219,14 @@ 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()
|
||||
.table("person", {
|
||||
make_pk_column<uint32_t>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<blob>("data")
|
||||
.table("person")
|
||||
.columns({
|
||||
attribute("id", basic_type::type_uint32),
|
||||
attribute("name", basic_type::type_varchar, 255),
|
||||
attribute("data", basic_type::type_blob)
|
||||
})
|
||||
.constraints({
|
||||
constraint("PK_person").primary_key({"id"})
|
||||
})
|
||||
.str(*db);
|
||||
|
||||
|
||||
+17
-19
@@ -9,9 +9,7 @@ TEST_CASE("Test create empty column", "[column]") {
|
||||
attribute c("name");
|
||||
|
||||
REQUIRE(c.name() == "name");
|
||||
REQUIRE(c.index() == -1);
|
||||
REQUIRE(c.type() == basic_type::type_null);
|
||||
REQUIRE(!c.reference_column());
|
||||
|
||||
c.change_type<std::string>(255);
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
@@ -24,39 +22,39 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||
attribute c(
|
||||
"name",
|
||||
basic_type::type_varchar,
|
||||
2,
|
||||
std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
|
||||
// 2,
|
||||
// std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
|
||||
{255, constraints::ForeignKey},
|
||||
null_option_type::NOT_NULL
|
||||
null_option_type::NotNull
|
||||
);
|
||||
REQUIRE(c.name() == "name");
|
||||
REQUIRE(c.index() == 2);
|
||||
REQUIRE(c.reference_column());
|
||||
REQUIRE(c.reference_column()->name() == "author");
|
||||
REQUIRE(c.reference_column()->table_name() == "books");
|
||||
// REQUIRE(c.index() == 2);
|
||||
// REQUIRE(c.reference_column());
|
||||
// REQUIRE(c.reference_column()->name() == "author");
|
||||
// REQUIRE(c.reference_column()->table_name() == "books");
|
||||
REQUIRE(c.type() == basic_type::type_varchar);
|
||||
REQUIRE(c.attributes().size() == 255);
|
||||
|
||||
auto c2 = c;
|
||||
REQUIRE(c2.name() == "name");
|
||||
REQUIRE(c2.index() == 2);
|
||||
REQUIRE(c2.reference_column());
|
||||
REQUIRE(c2.reference_column()->name() == "author");
|
||||
REQUIRE(c2.reference_column()->table_name() == "books");
|
||||
// REQUIRE(c2.index() == 2);
|
||||
// REQUIRE(c2.reference_column());
|
||||
// REQUIRE(c2.reference_column()->name() == "author");
|
||||
// REQUIRE(c2.reference_column()->table_name() == "books");
|
||||
REQUIRE(c2.type() == basic_type::type_varchar);
|
||||
REQUIRE(c2.attributes().size() == 255);
|
||||
|
||||
auto c3 = std::move(c2);
|
||||
REQUIRE(c3.name() == "name");
|
||||
REQUIRE(c3.index() == 2);
|
||||
REQUIRE(c3.reference_column());
|
||||
REQUIRE(c3.reference_column()->name() == "author");
|
||||
REQUIRE(c3.reference_column()->table_name() == "books");
|
||||
// REQUIRE(c3.index() == 2);
|
||||
// REQUIRE(c3.reference_column());
|
||||
// REQUIRE(c3.reference_column()->name() == "author");
|
||||
// REQUIRE(c3.reference_column()->table_name() == "books");
|
||||
REQUIRE(c3.type() == basic_type::type_varchar);
|
||||
REQUIRE(c3.attributes().size() == 255);
|
||||
|
||||
REQUIRE(c2.name().empty());
|
||||
REQUIRE(c2.index() == 2);
|
||||
REQUIRE(!c2.reference_column());
|
||||
// REQUIRE(c2.index() == 2);
|
||||
// REQUIRE(!c2.reference_column());
|
||||
REQUIRE(c2.attributes().size() == 255);
|
||||
}
|
||||
Reference in New Issue
Block a user