Skip to content

Commit 4cc3e87

Browse files
Explicitly set alias; fixes #80 (#82)
1 parent e4cf6c8 commit 4cc3e87

14 files changed

Lines changed: 46 additions & 26 deletions

include/sqlgen/dynamic/Column.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <optional>
55
#include <string>
6-
#include <vector>
76

87
#include "Type.hpp"
98
#include "types.hpp"

include/sqlgen/dynamic/Table.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#ifndef SQLGEN_DYNAMIC_TABLE_HPP_
22
#define SQLGEN_DYNAMIC_TABLE_HPP_
33

4+
#include <optional>
45
#include <string>
5-
#include <vector>
66

77
#include "Column.hpp"
88

99
namespace sqlgen::dynamic {
1010

1111
struct Table {
12-
std::optional<std::string> alias;
12+
std::optional<std::string> alias = std::nullopt;
1313
std::string name;
14-
std::optional<std::string> schema;
14+
std::optional<std::string> schema = std::nullopt;
1515
};
1616

1717
} // namespace sqlgen::dynamic

include/sqlgen/dynamic/create_table.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SQLGEN_DYNAMIC_CREATE_TABLE_HPP_
22
#define SQLGEN_DYNAMIC_CREATE_TABLE_HPP_
33

4+
#include <optional>
45
#include <string>
56
#include <vector>
67

@@ -12,13 +13,17 @@ namespace sqlgen::dynamic {
1213

1314
CreateTable create_table(const std::string& _table,
1415
const std::vector<Column>& _columns) {
15-
return CreateTable{.table = Table{.name = _table}, .columns = _columns};
16+
return CreateTable{
17+
.table =
18+
Table{.alias = std::nullopt, .name = _table, .schema = std::nullopt},
19+
.columns = _columns};
1620
}
1721

1822
CreateTable create_table(std::string& _schema, const std::string& _table,
1923
const std::vector<Column>& _columns) {
20-
return CreateTable{.table = Table{.name = _table, .schema = _schema},
21-
.columns = _columns};
24+
return CreateTable{
25+
.table = Table{.alias = std::nullopt, .name = _table, .schema = _schema},
26+
.columns = _columns};
2227
}
2328

2429
} // namespace sqlgen::dynamic

include/sqlgen/dynamic/select.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SQLGEN_DYNAMIC_SELECT_HPP_
22
#define SQLGEN_DYNAMIC_SELECT_HPP_
33

4+
#include <optional>
45
#include <string>
56
#include <vector>
67

@@ -16,7 +17,10 @@ SelectFrom select(const std::string& _table,
1617
for (const auto& name : _columns) {
1718
columns.emplace_back(Column{.name = name});
1819
}
19-
return SelectFrom{.table = Table{.name = _table}, .columns = columns};
20+
return SelectFrom{
21+
.table =
22+
Table{.alias = std::nullopt, .name = _table, .schema = std::nullopt},
23+
.columns = columns};
2024
}
2125

2226
SelectFrom select(const std::string& _schema, const std::string& _table,
@@ -25,7 +29,8 @@ SelectFrom select(const std::string& _schema, const std::string& _table,
2529
for (const auto& name : _columns) {
2630
columns.emplace_back(Column{.name = name});
2731
}
28-
return SelectFrom{.table = Table{.name = _table, .schema = _schema},
29-
.columns = columns};
32+
return SelectFrom{
33+
.table = Table{.alias = std::nullopt, .name = _table, .schema = _schema},
34+
.columns = columns};
3035
}
3136
} // namespace sqlgen::dynamic

include/sqlgen/transpilation/read_to_select_from.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ dynamic::SelectFrom read_to_select_from(const WhereType& _where = WhereType{},
4242
}));
4343

4444
return dynamic::SelectFrom{
45-
.table_or_query =
46-
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
45+
.table_or_query = dynamic::Table{.alias = std::nullopt,
46+
.name = get_tablename<T>(),
47+
.schema = get_schema<T>()},
4748
.fields = fields,
4849
.where = to_condition<std::remove_cvref_t<T>>(_where),
4950
.order_by = to_order_by<OrderByType>(),

include/sqlgen/transpilation/to_create_as.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ dynamic::CreateAs to_create_as(const dynamic::CreateAs::What _what,
2929
const LimitType& _limit) {
3030
return dynamic::CreateAs{
3131
.what = _what,
32-
.table_or_view =
33-
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
32+
.table_or_view = dynamic::Table{.alias = std::nullopt,
33+
.name = get_tablename<T>(),
34+
.schema = get_schema<T>()},
3435
.query = to_select_from<TableTupleType, AliasType, FieldsType,
3536
TableOrQueryType, JoinsType, WhereType,
3637
GroupByType, OrderByType, LimitType>(

include/sqlgen/transpilation/to_create_index.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SQLGEN_TRANSPILATION_TO_CREATE_INDEX_HPP_
22
#define SQLGEN_TRANSPILATION_TO_CREATE_INDEX_HPP_
33

4+
#include <optional>
45
#include <rfl.hpp>
56
#include <string>
67
#include <type_traits>
@@ -24,8 +25,9 @@ dynamic::CreateIndex to_create_index(const std::string& _name,
2425
const WhereType& _where) {
2526
return dynamic::CreateIndex{
2627
.name = _name,
27-
.table =
28-
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
28+
.table = dynamic::Table{.alias = std::nullopt,
29+
.name = get_tablename<T>(),
30+
.schema = get_schema<T>()},
2931
.columns = ColumnsType::to_vec(),
3032
.unique = _unique,
3133
.if_not_exists = _if_not_exists,

include/sqlgen/transpilation/to_create_table.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ dynamic::CreateTable to_create_table(const bool _if_not_exists = true) {
2929
"You cannot create a view using create_table(...).");
3030

3131
return dynamic::CreateTable{
32-
.table =
33-
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
32+
.table = dynamic::Table{.alias = std::nullopt,
33+
.name = get_tablename<T>(),
34+
.schema = get_schema<T>()},
3435
.columns = make_columns<Fields>(
3536
std::make_integer_sequence<int, rfl::tuple_size_v<Fields>>()),
3637
.if_not_exists = _if_not_exists};

include/sqlgen/transpilation/to_delete_from.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ dynamic::DeleteFrom to_delete_from(const WhereType& _where) {
2424
"You cannot call delete_from on a view.");
2525

2626
return dynamic::DeleteFrom{
27-
.table =
28-
dynamic::Table{.name = get_tablename<T>(), .schema = get_schema<T>()},
27+
.table = dynamic::Table{.alias = std::nullopt,
28+
.name = get_tablename<T>(),
29+
.schema = get_schema<T>()},
2930
.where = to_condition<std::remove_cvref_t<T>>(_where)};
3031
}
3132

include/sqlgen/transpilation/to_drop.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ dynamic::Drop to_drop(const dynamic::Drop::What _what, const bool _if_exists,
2323
return dynamic::Drop{.what = _what,
2424
.if_exists = _if_exists,
2525
.cascade = _cascade,
26-
.table = dynamic::Table{.name = get_tablename<T>(),
26+
.table = dynamic::Table{.alias = std::nullopt,
27+
.name = get_tablename<T>(),
2728
.schema = get_schema<T>()}};
2829
}
2930

0 commit comments

Comments
 (0)