mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-01 23:19:58 -06:00
Added dynamic query types
This commit is contained in:
19
include/dynamic/Column.hpp
Normal file
19
include/dynamic/Column.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef SQLGEN_DYNAMIC_COLUMN_HPP_
|
||||
#define SQLGEN_DYNAMIC_COLUMN_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Type.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
struct Column {
|
||||
std::string alias;
|
||||
std::string name;
|
||||
Type type;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
#endif
|
||||
19
include/dynamic/SelectFrom.hpp
Normal file
19
include/dynamic/SelectFrom.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef SQLGEN_DYNAMIC_SELECTFROM_HPP_
|
||||
#define SQLGEN_DYNAMIC_SELECTFROM_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Column.hpp"
|
||||
#include "Table.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
struct SelectFrom {
|
||||
Table table;
|
||||
std::vector<Column> columns;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
#endif
|
||||
17
include/dynamic/Table.hpp
Normal file
17
include/dynamic/Table.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SQLGEN_DYNAMIC_TABLE_HPP_
|
||||
#define SQLGEN_DYNAMIC_TABLE_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
struct Table {
|
||||
std::string alias;
|
||||
std::string name;
|
||||
std::string schema = "public";
|
||||
};
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
#endif
|
||||
18
include/dynamic/Type.hpp
Normal file
18
include/dynamic/Type.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef SQLGEN_DYNAMIC_TABLE_TYPE_HPP_
|
||||
#define SQLGEN_DYNAMIC_TABLE_TYPE_HPP_
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
using Type =
|
||||
std::variant<types::Unknown, types::Boolean, types::Float32, types::Float64,
|
||||
types::Int8, types::Int16, types::Int32, types::Int64,
|
||||
types::Text, types::Timestamp, types::TimestampWithTZ,
|
||||
types::VarChar>;
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
#endif
|
||||
31
include/dynamic/select.hpp
Normal file
31
include/dynamic/select.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
#define SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Column.hpp"
|
||||
#include "SelectFrom.hpp"
|
||||
#include "Table.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
SelectFrom select(const std::string& _table,
|
||||
const std::vector<std::string>& _columns) {
|
||||
std::vector<Column> columns;
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{.table = Table{.name = _table}, .columns = columns};
|
||||
}
|
||||
|
||||
SelectFrom select(const std::string& _schema, const std::string& _table,
|
||||
const std::vector<std::string>& _columns) {
|
||||
std::vector<Column> columns;
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{.table = Table{.name = _table, .schema = _schema},
|
||||
.columns = columns};
|
||||
}
|
||||
} // namespace sqlgen::dynamic
|
||||
66
include/dynamic/types.hpp
Normal file
66
include/dynamic/types.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef SQLGEN_DYNAMIC_TABLE_TYPES_HPP_
|
||||
#define SQLGEN_DYNAMIC_TABLE_TYPES_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace sqlgen::dynamic::types {
|
||||
|
||||
struct Properties {
|
||||
bool primary = false;
|
||||
bool nullable = false;
|
||||
};
|
||||
|
||||
// To be used as the default value.
|
||||
struct Unknown {};
|
||||
|
||||
struct Boolean {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Float32 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Float64 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Int8 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Int16 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Int32 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Int64 {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Text {
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct Timestamp {
|
||||
std::string tz;
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct TimestampWithTZ {
|
||||
std::string tz;
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
struct VarChar {
|
||||
uint16_t length;
|
||||
Properties properties;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::dynamic::types
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user