query preparations for std::optional
This commit is contained in:
+26
-29
@@ -5,33 +5,26 @@
|
||||
namespace matador::sql {
|
||||
|
||||
column::column(sql_function_t func, std::string name)
|
||||
: name_(std::move(name))
|
||||
, type_(data_type_t::type_int)
|
||||
, attributes_(utils::null_attributes)
|
||||
, function_(func) {}
|
||||
: name_(std::move(name)), type_(data_type_t::type_int), attributes_(utils::null_attributes), function_(func)
|
||||
{}
|
||||
|
||||
column::column(const char *name, std::string alias)
|
||||
: name_(name)
|
||||
, attributes_(utils::null_attributes)
|
||||
, alias_(std::move(alias)) {}
|
||||
: name_(name), attributes_(utils::null_attributes), alias_(std::move(alias))
|
||||
{}
|
||||
|
||||
column::column(std::string name, std::string alias)
|
||||
: name_(std::move(name))
|
||||
, attributes_(utils::null_attributes)
|
||||
, alias_(std::move(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) {}
|
||||
: name_(std::move(name)), type_(type), attributes_(attr)
|
||||
{}
|
||||
|
||||
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)) {}
|
||||
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))
|
||||
{}
|
||||
|
||||
const std::string &column::name() const
|
||||
{
|
||||
@@ -81,7 +74,7 @@ void column::alias(const std::string &as)
|
||||
std::string column::str() const
|
||||
{
|
||||
any_type_to_visitor<std::string> visitor;
|
||||
std::visit(visitor, const_cast<any_type&>(value_));
|
||||
std::visit(visitor, const_cast<any_type &>(value_));
|
||||
return visitor.result;
|
||||
}
|
||||
|
||||
@@ -100,26 +93,30 @@ 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)
|
||||
{
|
||||
return {name, type, attr};
|
||||
return {name, type, attr};
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return make_column(name, data_type_traits<std::string>::builtin_type(attr.size()), attr);
|
||||
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);
|
||||
}
|
||||
|
||||
template<>
|
||||
column make_pk_column<std::string>( const std::string& name, size_t size )
|
||||
column make_pk_column<std::string>(const std::string &name, size_t size)
|
||||
{
|
||||
return make_column<std::string>(name, { size, utils::constraints::FOREIGN_KEY });
|
||||
return make_column<std::string>(name, {size, utils::constraints::FOREIGN_KEY});
|
||||
}
|
||||
|
||||
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)
|
||||
[[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::PRIMARY_KEY | utils::constraints::NOT_NULL}};
|
||||
}
|
||||
}
|
||||
@@ -476,6 +476,9 @@ std::string build_create_column(const column &col, const dialect &d, column_cont
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::NOT_NULL)) {
|
||||
result.append(" NOT NULL");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::UNIQUE)) {
|
||||
result.append(" UNIQUE");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::PRIMARY_KEY)) {
|
||||
context.primary_keys.emplace_back(col.name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user