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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user