query builder create progress
This commit is contained in:
+7
-1
@@ -3,10 +3,16 @@
|
||||
#include "matador/utils/string.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
const std::string& dialect::token_at(dialect::token_t token) const {
|
||||
const std::string& dialect::token_at(dialect::token_t token) const
|
||||
{
|
||||
return tokens_.at(token);
|
||||
}
|
||||
|
||||
const std::string &dialect::data_type_at(data_type_t type) const
|
||||
{
|
||||
return data_types_.at(type);
|
||||
}
|
||||
|
||||
std::string dialect::prepare_identifier(const std::string &str) const
|
||||
{
|
||||
std::string result(str);
|
||||
|
||||
@@ -72,8 +72,25 @@ query_builder &query_builder::table(const std::string &table, std::initializer_l
|
||||
transition_to(state_t::QUERY_TABLE);
|
||||
|
||||
query_parts_.emplace_back(dialect_.token_at(dialect::token_t::TABLE) + " " + dialect_.prepare_identifier(table) + " ");
|
||||
// auto cols =
|
||||
|
||||
std::string result = "(";
|
||||
|
||||
for (const auto &col : columns) {
|
||||
result.append(dialect_.prepare_identifier(col.name()) + " " + dialect_.data_type_at(col.type()));
|
||||
if (col.attributes().size() > 0) {
|
||||
result.append("(" + std::to_string(col.attributes().size()) +")");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::NOT_NULL)) {
|
||||
result.append(" NOT NULL");
|
||||
}
|
||||
if (is_constraint_set(col.attributes().options(), utils::constraints::PRIMARY_KEY)) {
|
||||
result.append(" PRIMARY KEY");
|
||||
}
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
result += ")";
|
||||
query_parts_.emplace_back(result);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user