62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#ifndef QUERY_QUERY_DATA_HPP
|
|
#define QUERY_QUERY_DATA_HPP
|
|
|
|
#include "matador/object/attribute.hpp"
|
|
|
|
#include "matador/sql/resolver_service.hpp"
|
|
|
|
#include "matador/utils/types.hpp"
|
|
|
|
namespace matador::sql {
|
|
enum class sql_command {
|
|
Unknown,
|
|
Create,
|
|
CreateTable,
|
|
CreateSchema,
|
|
CreateSequence,
|
|
CreateDatabase,
|
|
Update,
|
|
Insert,
|
|
Delete,
|
|
Select,
|
|
Drop,
|
|
DropTable,
|
|
DropSchema,
|
|
DropSequence,
|
|
DropDatabase,
|
|
Alter,
|
|
AlterTable,
|
|
AlterSchema
|
|
};
|
|
|
|
enum class return_mode {
|
|
None,
|
|
GeneratedKeys,
|
|
Rows
|
|
};
|
|
|
|
struct query_context {
|
|
std::string sql;
|
|
sql_command command{};
|
|
std::string command_name{};
|
|
std::string schema_name{};
|
|
std::string table_name{};
|
|
std::vector<object::attribute> prototype{};
|
|
std::vector<std::string> bind_vars{};
|
|
std::vector<utils::database_type> bind_types{};
|
|
// 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; }
|
|
};
|
|
}
|
|
|
|
#endif //QUERY_QUERY_DATA_HPP
|