added returning token for insert query

This commit is contained in:
2026-02-15 18:34:12 +01:00
parent 9065355ee0
commit f38be4c6d9
16 changed files with 178 additions and 58 deletions
+2
View File
@@ -166,6 +166,7 @@ public:
[[nodiscard]] const std::string& primary_key() const;
[[nodiscard]] const std::string& references() const;
[[nodiscard]] const std::string& remove() const;
[[nodiscard]] const std::string& returning() const;
[[nodiscard]] const std::string& rollback() const;
[[nodiscard]] const std::string& schema() const;
[[nodiscard]] const std::string& select() const;
@@ -236,6 +237,7 @@ private:
{dialect_token::PrimaryKey, "PRIMARY KEY"},
{dialect_token::References, "REFERENCES"},
{dialect_token::Remove, "DELETE"},
{dialect_token::Returning, "RETURNING"},
{dialect_token::Rollback, "ROLLBACK TRANSACTION"},
{dialect_token::Schema, "SCHEMA"},
{dialect_token::Select, "SELECT"},
+1
View File
@@ -51,6 +51,7 @@ enum class dialect_token : uint8_t {
PrimaryKey,
References,
Remove,
Returning,
Rollback,
Schema,
Select,
+4 -1
View File
@@ -1,11 +1,14 @@
#ifndef MATADOR_EXECUTE_RESULT_HPP
#define MATADOR_EXECUTE_RESULT_HPP
#include "matador/utils/identifier.hpp"
#include <vector>
namespace matador::sql {
struct execute_result {
size_t affected_rows{};
std::vector<long long> insert_ids{};
std::vector<utils::identifier> generated_ids{};
};
}
#endif // MATADOR_EXECUTE_RESULT_HPP
+12 -3
View File
@@ -27,9 +27,10 @@ enum class sql_command {
AlterSchema
};
struct sql_command_info {
std::string sql;
sql_command command{};
enum class return_mode {
None,
GeneratedKeys,
Rows
};
struct query_context {
@@ -44,6 +45,14 @@ struct query_context {
// Data for resolving query result
std::shared_ptr<resolver_service> resolver{};
std::type_index result_type = typeid(void);
return_mode mode = return_mode::None;
[[nodiscard]] bool is_ddl() const { return command == sql_command::Create || command == sql_command::Alter; }
[[nodiscard]] bool is_dml() const { return command == sql_command::Insert || command == sql_command::Update || command == sql_command::Delete; }
[[nodiscard]] bool is_query() const { return command == sql_command::Select; }
[[nodiscard]] bool expects_rows() const { return mode == return_mode::Rows; }
[[nodiscard]] bool expects_generated_keys() const { return mode == return_mode::GeneratedKeys; }
};
}