moved column and table class from namespace sql to query
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
#ifndef QUERY_COLUMN_HPP
|
||||
#define QUERY_COLUMN_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class table;
|
||||
|
||||
enum class sql_function_t {
|
||||
None,
|
||||
Count,
|
||||
Avg,
|
||||
Sum,
|
||||
Min,
|
||||
Max
|
||||
};
|
||||
|
||||
class column {
|
||||
public:
|
||||
column(const char *name, const std::string& as = ""); // NOLINT(*-explicit-constructor)
|
||||
explicit column(std::string name, std::string as = "");
|
||||
column(sql_function_t func, std::string name); // NOLINT(*-explicit-constructor)
|
||||
column(const class table &tab, std::string name, std::string as = "");
|
||||
column(const std::shared_ptr<table> &t, std::string name, std::string as = "");
|
||||
|
||||
[[nodiscard]] bool equals(const column &x) const;
|
||||
|
||||
column& as(std::string a);
|
||||
|
||||
[[nodiscard]] const std::string& column_name() const;
|
||||
[[nodiscard]] std::string full_name() const;
|
||||
[[nodiscard]] const std::string& alias_name() const;
|
||||
[[nodiscard]] bool is_function() const;
|
||||
[[nodiscard]] sql_function_t function() const;
|
||||
[[nodiscard]] bool has_alias() const;
|
||||
[[nodiscard]] std::string alias() const;
|
||||
[[nodiscard]] std::shared_ptr<sql::table> table() const;
|
||||
void table(const std::shared_ptr<sql::table>& t);
|
||||
|
||||
private:
|
||||
std::shared_ptr<sql::table> table_;
|
||||
std::string name;
|
||||
std::string alias_;
|
||||
sql_function_t function_{sql_function_t::None};
|
||||
};
|
||||
|
||||
column operator ""_col(const char *name, size_t len);
|
||||
|
||||
}
|
||||
#endif //QUERY_COLUMN_HPP
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef QUERY_DIALECT_HPP
|
||||
#define QUERY_DIALECT_HPP
|
||||
|
||||
#include "matador/sql/column.hpp"
|
||||
#include "matador/sql/dialect_token.hpp"
|
||||
#include "matador/sql/sql_functions.hpp"
|
||||
|
||||
#include "matador/utils/basic_types.hpp"
|
||||
#include "matador/utils/types.hpp"
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
public:
|
||||
[[nodiscard]] const std::string& token_at(dialect_token token) const;
|
||||
[[nodiscard]] const std::string& data_type_at(utils::basic_type type) const;
|
||||
[[nodiscard]] const std::string& sql_function_at(sql_function_t func) const;
|
||||
|
||||
/**
|
||||
* Prepare sql dialect identifier for execution
|
||||
@@ -51,9 +52,7 @@ public:
|
||||
* @param col The identifier string to be prepared
|
||||
* @return The prepared string
|
||||
*/
|
||||
[[nodiscard]] std::string prepare_identifier(const column &col) const;
|
||||
[[nodiscard]] std::string prepare_identifier_string(const std::string &col) const;
|
||||
[[nodiscard]] std::string prepare_condition(const column &col) const;
|
||||
[[nodiscard]] std::string table_name(const std::string &table, const std::string &schema_name) const;
|
||||
|
||||
[[nodiscard]] const std::string& to_string(bool val) const;
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
#include <memory>
|
||||
|
||||
#include "matador/object/attribute_definition.hpp"
|
||||
|
||||
#include "matador/sql/connection_info.hpp"
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
#include "matador/utils/error.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
#include "matador/utils/version.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define QUERY_QUERY_DATA_HPP
|
||||
|
||||
#include "matador/object/attribute_definition.hpp"
|
||||
#include "matador/sql/table.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
@@ -35,7 +35,7 @@ struct query_context {
|
||||
sql_command command{};
|
||||
std::string command_name{};
|
||||
std::string schema_name{};
|
||||
sql::table table{""};
|
||||
std::string table_name{};
|
||||
std::vector<object::attribute_definition> prototype{};
|
||||
std::vector<std::string> result_vars{};
|
||||
std::vector<std::string> bind_vars{};
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "matador/utils/macro_map.hpp"
|
||||
|
||||
#include "matador/sql/table.hpp"
|
||||
#include "matador/sql/column.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
#include "matador/query/column.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class column;
|
||||
|
||||
class record final {
|
||||
private:
|
||||
using field_ref = std::reference_wrapper<field>;
|
||||
@@ -41,11 +39,11 @@ public:
|
||||
|
||||
[[nodiscard]] const std::vector<field_ref>& columns() const;
|
||||
|
||||
[[nodiscard]] const field& at(const sql::column &col) const;
|
||||
[[nodiscard]] const field& at(const std::string &name) const;
|
||||
[[nodiscard]] const field& at(size_t index) const;
|
||||
template<class Type>
|
||||
std::optional<Type> at(const column &col) const {
|
||||
return at(col).as<Type>();
|
||||
std::optional<Type> at(const std::string &name) const {
|
||||
return at(name).as<Type>();
|
||||
}
|
||||
template<class Type>
|
||||
std::optional<Type> at(const size_t index) const {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef MATADOR_SQL_FUNCTIONS_HPP
|
||||
#define MATADOR_SQL_FUNCTIONS_HPP
|
||||
|
||||
namespace matador::sql {
|
||||
enum class sql_function_t {
|
||||
None,
|
||||
Count,
|
||||
Avg,
|
||||
Sum,
|
||||
Min,
|
||||
Max
|
||||
};
|
||||
}
|
||||
#endif //MATADOR_SQL_FUNCTIONS_HPP
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef QUERY_TABLE_HPP
|
||||
#define QUERY_TABLE_HPP
|
||||
|
||||
#include "matador/sql/column.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class column;
|
||||
|
||||
class table {
|
||||
public:
|
||||
table() = default;
|
||||
table(const char *name); // NOLINT(*-explicit-constructor)
|
||||
table(std::string name); // NOLINT(*-explicit-constructor)
|
||||
table(const char *name, std::string as); // NOLINT(*-explicit-constructor)
|
||||
table(std::string name, std::string as); // NOLINT(*-explicit-constructor)
|
||||
table(std::string name, std::string as, const std::vector<column> &columns);
|
||||
|
||||
table& as(const std::string &a);
|
||||
|
||||
[[nodiscard]] bool operator==(const table &x) const;
|
||||
|
||||
[[nodiscard]] table as(const std::string &a) const;
|
||||
|
||||
[[nodiscard]] bool has_alias() const;
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const std::string& alias() const;
|
||||
[[nodiscard]] const std::vector<column>& columns() const;
|
||||
private:
|
||||
friend class column;
|
||||
|
||||
std::string name_;
|
||||
std::string alias_;
|
||||
|
||||
std::string schema_name_;
|
||||
std::vector<column> columns_;
|
||||
};
|
||||
|
||||
table operator ""_tab(const char *name, size_t len);
|
||||
|
||||
}
|
||||
|
||||
#endif //QUERY_TABLE_HPP
|
||||
Reference in New Issue
Block a user