diff --git a/include/dynamic/Column.hpp b/include/dynamic/Column.hpp new file mode 100644 index 0000000..32b7183 --- /dev/null +++ b/include/dynamic/Column.hpp @@ -0,0 +1,19 @@ +#ifndef SQLGEN_DYNAMIC_COLUMN_HPP_ +#define SQLGEN_DYNAMIC_COLUMN_HPP_ + +#include +#include + +#include "Type.hpp" + +namespace sqlgen::dynamic { + +struct Column { + std::string alias; + std::string name; + Type type; +}; + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/SelectFrom.hpp b/include/dynamic/SelectFrom.hpp new file mode 100644 index 0000000..d255188 --- /dev/null +++ b/include/dynamic/SelectFrom.hpp @@ -0,0 +1,19 @@ +#ifndef SQLGEN_DYNAMIC_SELECTFROM_HPP_ +#define SQLGEN_DYNAMIC_SELECTFROM_HPP_ + +#include +#include + +#include "Column.hpp" +#include "Table.hpp" + +namespace sqlgen::dynamic { + +struct SelectFrom { + Table table; + std::vector columns; +}; + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/Table.hpp b/include/dynamic/Table.hpp new file mode 100644 index 0000000..46249f9 --- /dev/null +++ b/include/dynamic/Table.hpp @@ -0,0 +1,17 @@ +#ifndef SQLGEN_DYNAMIC_TABLE_HPP_ +#define SQLGEN_DYNAMIC_TABLE_HPP_ + +#include +#include + +namespace sqlgen::dynamic { + +struct Table { + std::string alias; + std::string name; + std::string schema = "public"; +}; + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/Type.hpp b/include/dynamic/Type.hpp new file mode 100644 index 0000000..53d8fd3 --- /dev/null +++ b/include/dynamic/Type.hpp @@ -0,0 +1,18 @@ +#ifndef SQLGEN_DYNAMIC_TABLE_TYPE_HPP_ +#define SQLGEN_DYNAMIC_TABLE_TYPE_HPP_ + +#include + +#include "types.hpp" + +namespace sqlgen::dynamic { + +using Type = + std::variant; + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/select.hpp b/include/dynamic/select.hpp new file mode 100644 index 0000000..7f5c69f --- /dev/null +++ b/include/dynamic/select.hpp @@ -0,0 +1,31 @@ +#ifndef SQLGEN_DYNAMIC_SELECT_HPP_ +#define SQLGEN_DYNAMIC_SELECT_HPP_ + +#include +#include + +#include "Column.hpp" +#include "SelectFrom.hpp" +#include "Table.hpp" + +namespace sqlgen::dynamic { + +SelectFrom select(const std::string& _table, + const std::vector& _columns) { + std::vector 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& _columns) { + std::vector 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 diff --git a/include/dynamic/types.hpp b/include/dynamic/types.hpp new file mode 100644 index 0000000..54a92f0 --- /dev/null +++ b/include/dynamic/types.hpp @@ -0,0 +1,66 @@ +#ifndef SQLGEN_DYNAMIC_TABLE_TYPES_HPP_ +#define SQLGEN_DYNAMIC_TABLE_TYPES_HPP_ + +#include +#include + +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