extract not null constraint into enum
This commit is contained in:
+20
-13
@@ -16,14 +16,19 @@ column::column(std::string name, std::string alias)
|
||||
: name_(std::move(name)), attributes_(utils::null_attributes), alias_(std::move(alias))
|
||||
{}
|
||||
|
||||
column::column(std::string name, data_type_t type, utils::field_attributes attr)
|
||||
: name_(std::move(name)), type_(type), attributes_(attr)
|
||||
column::column(std::string name, data_type_t type, utils::field_attributes attr, null_option null_opt)
|
||||
: name_(std::move(name)), type_(type), attributes_(attr), null_option_(null_opt)
|
||||
{}
|
||||
|
||||
column::column(std::string name, data_type_t type, size_t index, std::string ref_table, std::string ref_column,
|
||||
utils::field_attributes attr)
|
||||
: name_(std::move(name)), index_(index), type_(type), attributes_(attr), ref_table_(std::move(ref_table)),
|
||||
ref_column_(std::move(ref_column))
|
||||
utils::field_attributes attr, null_option null_opt)
|
||||
: name_(std::move(name))
|
||||
, index_(index)
|
||||
, type_(type)
|
||||
, attributes_(attr)
|
||||
, null_option_(null_opt)
|
||||
, ref_table_(std::move(ref_table))
|
||||
, ref_column_(std::move(ref_column))
|
||||
{}
|
||||
|
||||
const std::string &column::name() const
|
||||
@@ -41,6 +46,11 @@ const utils::field_attributes &column::attributes() const
|
||||
return attributes_;
|
||||
}
|
||||
|
||||
bool column::is_nullable() const
|
||||
{
|
||||
return null_option_ == null_option::NULLABLE;
|
||||
}
|
||||
|
||||
data_type_t column::type() const
|
||||
{
|
||||
return type_;
|
||||
@@ -93,18 +103,15 @@ column operator "" _col(const char *name, size_t len)
|
||||
return {std::string(name, len)};
|
||||
}
|
||||
|
||||
column make_column(const std::string &name, data_type_t type, utils::field_attributes attr)
|
||||
column make_column(const std::string &name, data_type_t type, utils::field_attributes attr, null_option null_opt)
|
||||
{
|
||||
return {name, type, attr};
|
||||
return {name, type, attr, null_opt};
|
||||
}
|
||||
|
||||
template<>
|
||||
column make_column<std::string>(const std::string &name, utils::field_attributes attr)
|
||||
column make_column<std::string>(const std::string &name, utils::field_attributes attr, null_option null_opt)
|
||||
{
|
||||
if (attr.options() == utils::constraints::NONE) {
|
||||
return make_column(name, data_type_traits<std::string>::builtin_type(attr.size()), { attr.size(), utils::constraints::NOT_NULL});
|
||||
}
|
||||
return make_column(name, data_type_traits<std::string>::builtin_type(attr.size()), attr);
|
||||
return make_column(name, data_type_traits<std::string>::builtin_type(attr.size()), attr, null_opt);
|
||||
}
|
||||
|
||||
template<>
|
||||
@@ -117,6 +124,6 @@ template<>
|
||||
[[maybe_unused]] column make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table,
|
||||
const std::string &ref_column)
|
||||
{
|
||||
return {name, data_type_traits<std::string>::builtin_type(size), 0, ref_table, ref_column, {size, utils::constraints::PRIMARY_KEY | utils::constraints::NOT_NULL}};
|
||||
return {name, data_type_traits<std::string>::builtin_type(size), 0, ref_table, ref_column, {size, utils::constraints::FOREIGN_KEY}, null_option::NOT_NULL};
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ column_generator::column_generator(std::vector<column> &columns, const table_rep
|
||||
|
||||
void column_generator::on_primary_key(const char *id, std::string &pk, size_t size)
|
||||
{
|
||||
on_attribute(id, pk, { size, utils::constraints::PRIMARY_KEY | utils::constraints::NOT_NULL });
|
||||
on_attribute(id, pk, { size, utils::constraints::PRIMARY_KEY });
|
||||
}
|
||||
|
||||
void column_generator::on_revision(const char *id, unsigned long long int &x)
|
||||
|
||||
@@ -473,7 +473,7 @@ std::string build_create_column(const column &col, const dialect &d, column_cont
|
||||
if (col.attributes().size() > 0) {
|
||||
result.append("(" + std::to_string(col.attributes().size()) + ")");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::NOT_NULL)) {
|
||||
if (!col.is_nullable()) {
|
||||
result.append(" NOT NULL");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::UNIQUE)) {
|
||||
|
||||
Reference in New Issue
Block a user