mirror of
https://github.com/getml/sqlgen.git
synced 2026-05-18 05:59:02 -05:00
committed by
GitHub
parent
e4cf6c802b
commit
4cc3e871c3
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Type.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#ifndef SQLGEN_DYNAMIC_TABLE_HPP_
|
||||
#define SQLGEN_DYNAMIC_TABLE_HPP_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Column.hpp"
|
||||
|
||||
namespace sqlgen::dynamic {
|
||||
|
||||
struct Table {
|
||||
std::optional<std::string> alias;
|
||||
std::optional<std::string> alias = std::nullopt;
|
||||
std::string name;
|
||||
std::optional<std::string> schema;
|
||||
std::optional<std::string> schema = std::nullopt;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SQLGEN_DYNAMIC_CREATE_TABLE_HPP_
|
||||
#define SQLGEN_DYNAMIC_CREATE_TABLE_HPP_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -12,13 +13,17 @@ namespace sqlgen::dynamic {
|
||||
|
||||
CreateTable create_table(const std::string& _table,
|
||||
const std::vector<Column>& _columns) {
|
||||
return CreateTable{.table = Table{.name = _table}, .columns = _columns};
|
||||
return CreateTable{
|
||||
.table =
|
||||
Table{.alias = std::nullopt, .name = _table, .schema = std::nullopt},
|
||||
.columns = _columns};
|
||||
}
|
||||
|
||||
CreateTable create_table(std::string& _schema, const std::string& _table,
|
||||
const std::vector<Column>& _columns) {
|
||||
return CreateTable{.table = Table{.name = _table, .schema = _schema},
|
||||
.columns = _columns};
|
||||
return CreateTable{
|
||||
.table = Table{.alias = std::nullopt, .name = _table, .schema = _schema},
|
||||
.columns = _columns};
|
||||
}
|
||||
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
#define SQLGEN_DYNAMIC_SELECT_HPP_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,10 @@ SelectFrom select(const std::string& _table,
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{.table = Table{.name = _table}, .columns = columns};
|
||||
return SelectFrom{
|
||||
.table =
|
||||
Table{.alias = std::nullopt, .name = _table, .schema = std::nullopt},
|
||||
.columns = columns};
|
||||
}
|
||||
|
||||
SelectFrom select(const std::string& _schema, const std::string& _table,
|
||||
@@ -25,7 +29,8 @@ SelectFrom select(const std::string& _schema, const std::string& _table,
|
||||
for (const auto& name : _columns) {
|
||||
columns.emplace_back(Column{.name = name});
|
||||
}
|
||||
return SelectFrom{.table = Table{.name = _table, .schema = _schema},
|
||||
.columns = columns};
|
||||
return SelectFrom{
|
||||
.table = Table{.alias = std::nullopt, .name = _table, .schema = _schema},
|
||||
.columns = columns};
|
||||
}
|
||||
} // namespace sqlgen::dynamic
|
||||
|
||||
@@ -42,8 +42,9 @@ dynamic::SelectFrom read_to_select_from(const WhereType& _where = WhereType{},
|
||||
}));
|
||||
|
||||
return dynamic::SelectFrom{
|
||||
.table_or_query =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table_or_query = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.fields = fields,
|
||||
.where = to_condition<std::remove_cvref_t<T>>(_where),
|
||||
.order_by = to_order_by<OrderByType>(),
|
||||
|
||||
@@ -29,8 +29,9 @@ dynamic::CreateAs to_create_as(const dynamic::CreateAs::What _what,
|
||||
const LimitType& _limit) {
|
||||
return dynamic::CreateAs{
|
||||
.what = _what,
|
||||
.table_or_view =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table_or_view = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.query = to_select_from<TableTupleType, AliasType, FieldsType,
|
||||
TableOrQueryType, JoinsType, WhereType,
|
||||
GroupByType, OrderByType, LimitType>(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SQLGEN_TRANSPILATION_TO_CREATE_INDEX_HPP_
|
||||
#define SQLGEN_TRANSPILATION_TO_CREATE_INDEX_HPP_
|
||||
|
||||
#include <optional>
|
||||
#include <rfl.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -24,8 +25,9 @@ dynamic::CreateIndex to_create_index(const std::string& _name,
|
||||
const WhereType& _where) {
|
||||
return dynamic::CreateIndex{
|
||||
.name = _name,
|
||||
.table =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.columns = ColumnsType::to_vec(),
|
||||
.unique = _unique,
|
||||
.if_not_exists = _if_not_exists,
|
||||
|
||||
@@ -29,8 +29,9 @@ dynamic::CreateTable to_create_table(const bool _if_not_exists = true) {
|
||||
"You cannot create a view using create_table(...).");
|
||||
|
||||
return dynamic::CreateTable{
|
||||
.table =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.columns = make_columns<Fields>(
|
||||
std::make_integer_sequence<int, rfl::tuple_size_v<Fields>>()),
|
||||
.if_not_exists = _if_not_exists};
|
||||
|
||||
@@ -24,8 +24,9 @@ dynamic::DeleteFrom to_delete_from(const WhereType& _where) {
|
||||
"You cannot call delete_from on a view.");
|
||||
|
||||
return dynamic::DeleteFrom{
|
||||
.table =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.where = to_condition<std::remove_cvref_t<T>>(_where)};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ dynamic::Drop to_drop(const dynamic::Drop::What _what, const bool _if_exists,
|
||||
return dynamic::Drop{.what = _what,
|
||||
.if_exists = _if_exists,
|
||||
.cascade = _cascade,
|
||||
.table = dynamic::Table{.name = get_tablename<T>(),
|
||||
.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()}};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ InsertOrWrite to_insert_or_write(bool or_replace) {
|
||||
const auto get_name = [](const auto& _col) { return _col.name; };
|
||||
|
||||
auto result = InsertOrWrite{
|
||||
.table =
|
||||
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
|
||||
.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.columns =
|
||||
sqlgen::internal::collect::vector(columns | transform(get_name))};
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ struct ToJoin<TableTupleType, TableWrapper<TableType>> {
|
||||
|
||||
return dynamic::Join{
|
||||
.how = _how,
|
||||
.table_or_query = dynamic::Table{.name = get_tablename<T>(),
|
||||
.table_or_query = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.alias = Alias().str(),
|
||||
.on = to_condition<TableTupleType>(_join.on)};
|
||||
|
||||
@@ -19,7 +19,8 @@ template <class TableType>
|
||||
struct ToTableOrQuery<TableWrapper<TableType>> {
|
||||
dynamic::SelectFrom::TableOrQueryType operator()(const auto&) {
|
||||
using T = std::remove_cvref_t<TableType>;
|
||||
return dynamic::Table{.name = get_tablename<T>(),
|
||||
return dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,8 @@ template <class T, class SetsType, class WhereType>
|
||||
requires std::is_class_v<std::remove_cvref_t<T>> &&
|
||||
std::is_aggregate_v<std::remove_cvref_t<T>>
|
||||
dynamic::Update to_update(const SetsType& _sets, const WhereType& _where) {
|
||||
return dynamic::Update{.table = dynamic::Table{.name = get_tablename<T>(),
|
||||
return dynamic::Update{.table = dynamic::Table{.alias = std::nullopt,
|
||||
.name = get_tablename<T>(),
|
||||
.schema = get_schema<T>()},
|
||||
.sets = to_sets<T>(_sets),
|
||||
.where = to_condition<std::remove_cvref_t<T>>(_where)};
|
||||
|
||||
Reference in New Issue
Block a user