Skip to content

Commit

Permalink
Merge pull request #1327 from fnc12/correct-self-join-example
Browse files Browse the repository at this point in the history
Corrected self-join example
  • Loading branch information
trueqbit authored Jun 22, 2024
2 parents 8f71f41 + 25cfaa2 commit 64342a0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions examples/self_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct Employee {
std::string fax;
std::string email;
};
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
inline constexpr sqlite_orm::orm_table_reference auto employee = sqlite_orm::c<Employee>();
#endif

/**
* This is how custom alias is made:
Expand Down Expand Up @@ -208,9 +211,10 @@ int main() {
// ON m.ReportsTo = employees.EmployeeId
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
constexpr orm_table_alias auto m = "m"_alias.for_<Employee>();
auto firstNames = storage.select(columns(m->*&Employee::firstName || " " || m->*&Employee::lastName,
&Employee::firstName || " " || &Employee::lastName),
inner_join<m>(on(m->*&Employee::reportsTo == &Employee::employeeId)));
auto firstNames =
storage.select(columns(m->*&Employee::firstName || " " || m->*&Employee::lastName,
employee->*&Employee::firstName || " " || employee->*&Employee::lastName),
inner_join<m>(on(m->*&Employee::reportsTo == employee->*&Employee::employeeId)));
cout << "firstNames count = " << firstNames.size() << endl;
for(auto& row: firstNames) {
cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl;
Expand All @@ -219,7 +223,7 @@ int main() {
using als = alias_m<Employee>;
auto firstNames = storage.select(
columns(alias_column<als>(&Employee::firstName) || " " || alias_column<als>(&Employee::lastName),
&Employee::firstName || " " || &Employee::lastName),
&Employee::firstName || c(" ") || &Employee::lastName),
inner_join<als>(on(alias_column<als>(&Employee::reportsTo) == &Employee::employeeId)));
cout << "firstNames count = " << firstNames.size() << endl;
for(auto& row: firstNames) {
Expand All @@ -240,9 +244,10 @@ int main() {
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
static_assert(std::is_empty_v<custom_alias<Employee>>);
constexpr orm_table_alias auto emp = custom_alias<Employee>{};
auto firstNames = storage.select(columns(emp->*&Employee::firstName || " " || emp->*&Employee::lastName,
&Employee::firstName || " " || &Employee::lastName),
inner_join<emp>(on(emp->*&Employee::reportsTo == &Employee::employeeId)));
auto firstNames =
storage.select(columns(emp->*&Employee::firstName || " " || emp->*&Employee::lastName,
employee->*&Employee::firstName || " " || employee->*&Employee::lastName),
inner_join<emp>(on(emp->*&Employee::reportsTo == employee->*&Employee::employeeId)));
cout << "firstNames count = " << firstNames.size() << endl;
for(auto& row: firstNames) {
cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl;
Expand All @@ -251,7 +256,7 @@ int main() {
using als = custom_alias<Employee>;
auto firstNames = storage.select(
columns(alias_column<als>(&Employee::firstName) || " " || alias_column<als>(&Employee::lastName),
&Employee::firstName || " " || &Employee::lastName),
&Employee::firstName || c(" ") || &Employee::lastName),
inner_join<als>(on(alias_column<als>(&Employee::reportsTo) == &Employee::employeeId)));
cout << "firstNames count = " << firstNames.size() << endl;
for(auto& row: firstNames) {
Expand Down

0 comments on commit 64342a0

Please sign in to comment.