From ab5bc10e1df83af53a5ffa07876943013623c107 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Wed, 19 Mar 2025 06:44:13 +0100 Subject: [PATCH] Added CreateTable --- include/dynamic/CreateTable.hpp | 21 +++++++++++++++++++++ include/dynamic/SelectFrom.hpp | 4 ++-- include/dynamic/Table.hpp | 8 +++++--- include/dynamic/create_table.hpp | 26 ++++++++++++++++++++++++++ include/dynamic/select.hpp | 22 +++++++++++----------- 5 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 include/dynamic/CreateTable.hpp create mode 100644 include/dynamic/create_table.hpp diff --git a/include/dynamic/CreateTable.hpp b/include/dynamic/CreateTable.hpp new file mode 100644 index 0000000..b5de2ce --- /dev/null +++ b/include/dynamic/CreateTable.hpp @@ -0,0 +1,21 @@ +#ifndef SQLGEN_DYNAMIC_CREATETABLE_HPP_ +#define SQLGEN_DYNAMIC_CREATETABLE_HPP_ + +#include +#include + +#include "Column.hpp" +#include "Table.hpp" + +namespace sqlgen::dynamic { + +struct CreateTable { + Table table; + std::vector columns; + bool if_not_exists = true; + // TODO: Constraints +}; + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/SelectFrom.hpp b/include/dynamic/SelectFrom.hpp index d255188..672ab79 100644 --- a/include/dynamic/SelectFrom.hpp +++ b/include/dynamic/SelectFrom.hpp @@ -10,8 +10,8 @@ namespace sqlgen::dynamic { struct SelectFrom { - Table table; - std::vector columns; + Table table; + std::vector columns; }; } // namespace sqlgen::dynamic diff --git a/include/dynamic/Table.hpp b/include/dynamic/Table.hpp index 46249f9..794b9db 100644 --- a/include/dynamic/Table.hpp +++ b/include/dynamic/Table.hpp @@ -4,12 +4,14 @@ #include #include +#include "Column.hpp" + namespace sqlgen::dynamic { struct Table { - std::string alias; - std::string name; - std::string schema = "public"; + std::string alias; + std::string name; + std::string schema = "public"; }; } // namespace sqlgen::dynamic diff --git a/include/dynamic/create_table.hpp b/include/dynamic/create_table.hpp new file mode 100644 index 0000000..02be394 --- /dev/null +++ b/include/dynamic/create_table.hpp @@ -0,0 +1,26 @@ +#ifndef SQLGEN_DYNAMIC_CREATE_TABLE_HPP_ +#define SQLGEN_DYNAMIC_CREATE_TABLE_HPP_ + +#include +#include + +#include "Column.hpp" +#include "CreateTable.hpp" +#include "Table.hpp" + +namespace sqlgen::dynamic { + +CreateTable create_table(const std::string& _table, + const std::vector& _columns) { + return CreateTable{.table = Table{.name = _table}, .columns = _columns}; +} + +CreateTable create_table(std::string& _schema, const std::string& _table, + const std::vector& _columns) { + return CreateTable{.table = Table{.name = _table, .schema = _schema}, + .columns = _columns}; +} + +} // namespace sqlgen::dynamic + +#endif diff --git a/include/dynamic/select.hpp b/include/dynamic/select.hpp index 7f5c69f..2947d85 100644 --- a/include/dynamic/select.hpp +++ b/include/dynamic/select.hpp @@ -12,20 +12,20 @@ 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}; + 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}; + 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