77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#include "matador/query/builder.hpp"
|
|
|
|
namespace matador::query {
|
|
|
|
column_builder::column_builder(std::string column_name, const utils::basic_type type, const size_t size)
|
|
: column_name_(std::move(column_name))
|
|
, type_(type)
|
|
, size_(size) {}
|
|
|
|
column_builder::operator class query::table_column() const {
|
|
return {nullptr, column_name_, type_, {size_, constraints_}};
|
|
}
|
|
|
|
column_builder& column_builder::not_null() {
|
|
constraints_ |= utils::constraints::NotNull;
|
|
return *this;
|
|
}
|
|
|
|
column_builder & column_builder::primary_key() {
|
|
constraints_ |= utils::constraints::PrimaryKey;
|
|
return *this;
|
|
}
|
|
|
|
column_builder & column_builder::unique() {
|
|
constraints_ |= utils::constraints::Unique;
|
|
return *this;
|
|
}
|
|
|
|
table_builder::table_builder(std::string name)
|
|
: table_name( std::move(name) ) {}
|
|
|
|
|
|
table_builder::operator class query::table() const {
|
|
return {table_name, {}};
|
|
}
|
|
|
|
constraint_builder& constraint_builder::constraint( std::string name ) {
|
|
constraint_name_ = std::move(name);
|
|
return *this;
|
|
}
|
|
|
|
constraint_builder& constraint_builder::primary_key( std::string name ) {
|
|
column_name_ = std::move(name);
|
|
type_ = utils::constraints::PrimaryKey;
|
|
return *this;
|
|
}
|
|
|
|
constraint_builder& constraint_builder::foreign_key( std::string name ) {
|
|
column_name_ = std::move(name);
|
|
type_ = utils::constraints::ForeignKey;
|
|
return *this;
|
|
}
|
|
|
|
constraint_builder& constraint_builder::references( std::string table, std::string column ) {
|
|
this->ref_table_name_ = std::move(table);
|
|
this->ref_column_name_ = std::move(column);
|
|
return *this;
|
|
}
|
|
|
|
constraint_builder::operator table_constraint() const {
|
|
return {constraint_name_, column_name_, ref_table_name_, type_, ref_table_name_, ref_column_name_};
|
|
}
|
|
|
|
constraint_builder constraint( std::string name ) {
|
|
constraint_builder builder;
|
|
return builder.constraint(std::move(name));
|
|
}
|
|
|
|
table_builder table( std::string name ) {
|
|
return table_builder(std::move(name));
|
|
}
|
|
|
|
column_builder column(std::string name, const utils::basic_type type, const size_t size) {
|
|
return column_builder(std::move(name), type, size);
|
|
}
|
|
|
|
} |