added returning token for insert query
This commit is contained in:
@@ -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"},
|
||||
|
||||
@@ -51,6 +51,7 @@ enum class dialect_token : uint8_t {
|
||||
PrimaryKey,
|
||||
References,
|
||||
Remove,
|
||||
Returning,
|
||||
Rollback,
|
||||
Schema,
|
||||
Select,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user