50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#ifndef QUERY_COLUMN_HPP
|
|
#define QUERY_COLUMN_HPP
|
|
|
|
#include <string>
|
|
|
|
namespace matador::sql {
|
|
|
|
enum class sql_function_t {
|
|
NONE,
|
|
COUNT,
|
|
AVG,
|
|
SUM,
|
|
MIN,
|
|
MAX
|
|
};
|
|
|
|
struct column
|
|
{
|
|
column(const char *name) : name(name) {} // NOLINT(*-explicit-constructor)
|
|
column(std::string name) : name(std::move(name)) {} // NOLINT(*-explicit-constructor)
|
|
column(sql_function_t func, std::string name) : name(std::move(name)), function_(func) {} // NOLINT(*-explicit-constructor)
|
|
column(std::string table_name, std::string name, std::string as)
|
|
: table(std::move(table_name))
|
|
, name(std::move(name))
|
|
, alias(std::move(as)) {}
|
|
column(std::string table_name, const char* name, std::string as)
|
|
: table(std::move(table_name))
|
|
, name(name)
|
|
, alias(std::move(as)) {}
|
|
|
|
column& as(std::string a) {
|
|
alias = std::move(a);
|
|
return *this;
|
|
}
|
|
|
|
[[nodiscard]] bool is_function() const {
|
|
return function_ != sql_function_t::NONE;
|
|
}
|
|
|
|
std::string 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
|