14 return std::make_unique<postgresql_dialect>();
16 return std::make_unique<sqlite_dialect>();
18 throw std::invalid_argument(
"Unsupported database type for SQL dialect");
25 return "$" + std::to_string(index);
30 result.reserve(name.size() + 2);
45 result.reserve(str.size());
49 }
else if (c ==
'\\') {
60 return " RETURNING *";
66 const std::vector<std::string>& conflict_columns,
67 const std::vector<std::string>& update_columns)
const {
69 if (conflict_columns.empty()) {
73 std::string result =
"ON CONFLICT (";
74 for (
size_t i = 0; i < conflict_columns.size(); ++i) {
75 if (i > 0) result +=
", ";
80 if (update_columns.empty()) {
81 result +=
" DO NOTHING";
83 result +=
" DO UPDATE SET ";
84 for (
size_t i = 0; i < update_columns.size(); ++i) {
85 if (i > 0) result +=
", ";
87 result += quoted +
" = EXCLUDED." + quoted;
94 std::string clause =
"LIMIT " + std::to_string(limit);
96 clause +=
" OFFSET " + std::to_string(offset);
106 return "CURRENT_TIMESTAMP";
115 if (feature ==
"window_functions")
return true;
116 if (feature ==
"cte")
return true;
117 if (feature ==
"recursive_cte")
return true;
118 if (feature ==
"json")
return true;
119 if (feature ==
"full_outer_join")
return true;
120 if (feature ==
"returning")
return true;
121 if (feature ==
"array")
return true;
122 if (feature ==
"upsert")
return true;
129 return "?" + std::to_string(index);
134 result.reserve(name.size() + 2);
136 for (
char c : name) {
149 result.reserve(str.size());
162 if (column.empty()) {
163 return " RETURNING *";
169 const std::vector<std::string>& conflict_columns,
170 const std::vector<std::string>& update_columns)
const {
172 if (conflict_columns.empty()) {
176 std::string result =
"ON CONFLICT (";
177 for (
size_t i = 0; i < conflict_columns.size(); ++i) {
178 if (i > 0) result +=
", ";
183 if (update_columns.empty()) {
184 result +=
" DO NOTHING";
186 result +=
" DO UPDATE SET ";
187 for (
size_t i = 0; i < update_columns.size(); ++i) {
188 if (i > 0) result +=
", ";
190 result += quoted +
" = excluded." + quoted;
197 std::string clause =
"LIMIT " + std::to_string(limit);
199 clause +=
" OFFSET " + std::to_string(offset);
205 return "AUTOINCREMENT";
209 return "CURRENT_TIMESTAMP";
217 if (feature ==
"window_functions")
return true;
218 if (feature ==
"cte")
return true;
219 if (feature ==
"recursive_cte")
return true;
220 if (feature ==
"json")
return true;
221 if (feature ==
"full_outer_join")
return false;
222 if (feature ==
"returning")
return true;
223 if (feature ==
"array")
return false;
224 if (feature ==
"upsert")
return true;
std::string quote_identifier(std::string_view name) const override
Quote an identifier (table or column name)
std::string auto_increment() const override
Get auto-increment column definition.
bool supports_feature(const std::string &feature) const override
Check if database supports specific feature.
std::string returning_clause(std::string_view column="") const override
Generate RETURNING clause for INSERT/UPDATE.
std::string upsert_clause(const std::vector< std::string > &conflict_columns, const std::vector< std::string > &update_columns) const override
Generate UPSERT (INSERT OR UPDATE) clause.
std::string concat_operator() const override
Get string concatenation operator.
std::string current_timestamp() const override
Get current timestamp function.
std::string limit_clause(size_t limit, size_t offset) const override
Generate LIMIT clause.
std::string placeholder(int index) const override
Generate parameter placeholder.
std::string escape_string(std::string_view str) const override
Escape a string value for safe SQL inclusion.
static std::unique_ptr< sql_dialect > create(database_types type)
Factory method to create appropriate dialect.
std::string upsert_clause(const std::vector< std::string > &conflict_columns, const std::vector< std::string > &update_columns) const override
Generate UPSERT (INSERT OR UPDATE) clause.
bool supports_feature(const std::string &feature) const override
Check if database supports specific feature.
std::string quote_identifier(std::string_view name) const override
Quote an identifier (table or column name)
std::string current_timestamp() const override
Get current timestamp function.
std::string concat_operator() const override
Get string concatenation operator.
std::string placeholder(int index) const override
Generate parameter placeholder.
std::string auto_increment() const override
Get auto-increment column definition.
std::string returning_clause(std::string_view column="") const override
Generate RETURNING clause for INSERT/UPDATE.
std::string limit_clause(size_t limit, size_t offset) const override
Generate LIMIT clause.
std::string escape_string(std::string_view str) const override
Escape a string value for safe SQL inclusion.
database_types
Represents various database backends or modes.
@ sqlite
Indicates a SQLite database.
@ postgres
Indicates a PostgreSQL database.