Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dev/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ namespace sqlite_orm {
return {};
}

template<auto t>
template<orm_table_reference auto t>
[[nodiscard]] consteval auto for_() const {
using T = auto_decay_table_ref_t<t>;
return recordset_alias<T, A, X...>{};
}

template<orm_recordset_alias auto t>
[[nodiscard]] consteval auto for_() const {
using T = std::remove_const_t<decltype(t)>;
return recordset_alias<T, A, X...>{};
Expand Down
8 changes: 8 additions & 0 deletions dev/ast/into.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../functional/cxx_type_traits_polyfill.h"
#include "../table_reference.h"

namespace sqlite_orm {
namespace internal {
Expand All @@ -20,4 +21,11 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
internal::into_t<T> into() {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_table_reference auto table>
auto into() {
return into<internal::auto_decay_table_ref_t<table>>();
}
#endif
}
14 changes: 14 additions & 0 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,25 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto alias>
auto cross_join() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no tests or example with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are tests in tests/static_tests/column_pointer.cpp specifically for expressions that involve table references. Otherwise, there are already the usual tests and examples for cross and natural joins.

return cross_join<internal::auto_decay_table_ref_t<alias>>();
}
#endif

template<class T>
internal::natural_join_t<T> natural_join() {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto alias>
auto natural_join() {
return natural_join<internal::auto_decay_table_ref_t<alias>>();
}
#endif

template<class T, class O>
internal::left_join_t<T, O> left_join(O o) {
return {std::move(o)};
Expand Down
31 changes: 30 additions & 1 deletion include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,13 @@ namespace sqlite_orm {
return {};
}

template<auto t>
template<orm_table_reference auto t>
[[nodiscard]] consteval auto for_() const {
using T = auto_decay_table_ref_t<t>;
return recordset_alias<T, A, X...>{};
}

template<orm_recordset_alias auto t>
[[nodiscard]] consteval auto for_() const {
using T = std::remove_const_t<decltype(t)>;
return recordset_alias<T, A, X...>{};
Expand Down Expand Up @@ -6053,11 +6059,25 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto alias>
auto cross_join() {
return cross_join<internal::auto_decay_table_ref_t<alias>>();
}
#endif

template<class T>
internal::natural_join_t<T> natural_join() {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_refers_to_recordset auto alias>
auto natural_join() {
return natural_join<internal::auto_decay_table_ref_t<alias>>();
}
#endif

template<class T, class O>
internal::left_join_t<T, O> left_join(O o) {
return {std::move(o)};
Expand Down Expand Up @@ -6342,6 +6362,8 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {

// #include "../functional/cxx_type_traits_polyfill.h"

// #include "../table_reference.h"

namespace sqlite_orm {
namespace internal {

Expand All @@ -6360,6 +6382,13 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
internal::into_t<T> into() {
return {};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<orm_table_reference auto table>
auto into() {
return into<internal::auto_decay_table_ref_t<table>>();
}
#endif
}

namespace sqlite_orm {
Expand Down
2 changes: 2 additions & 0 deletions tests/static_tests/alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ TEST_CASE("aliases") {
SECTION("table alias expressions") {
constexpr auto derived_user = c<DerivedUser>();
constexpr auto d_alias = "d"_alias.for_<DerivedUser>();
constexpr auto tableref_alias = "d"_alias.for_<derived_user>();
STATIC_REQUIRE(std::is_same_v<decltype(tableref_alias), decltype(d_alias)>);
using d_alias_type = decltype("d"_alias.for_<DerivedUser>());
runTest<internal::from_t<d_alias_type>>(from<d_alias>());
runTest<internal::asterisk_t<d_alias_type>>(asterisk<d_alias>());
Expand Down
3 changes: 3 additions & 0 deletions tests/static_tests/column_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ TEST_CASE("column pointers") {
SECTION("table reference expressions") {
runTest<internal::base_table<DerivedUser, std::false_type>>(make_table<derived_user>("derived_user"));
runTest<internal::from_t<DerivedUser>>(from<derived_user>());
runTest<internal::into_t<DerivedUser>>(into<derived_user>());
runTest<internal::asterisk_t<DerivedUser>>(asterisk<derived_user>());
runTest<internal::object_t<DerivedUser>>(object<derived_user>());
runTest<internal::count_asterisk_t<DerivedUser>>(count<derived_user>());
Expand All @@ -162,6 +163,8 @@ TEST_CASE("column pointers") {
left_outer_join<derived_user>(using_(derived_user->*&DerivedUser::id)));
runTest<internal::inner_join_t<DerivedUser, using_t<DerivedUser, decltype(&DerivedUser::id)>>>(
inner_join<derived_user>(using_(derived_user->*&DerivedUser::id)));
runTest<internal::cross_join_t<DerivedUser>>(cross_join<derived_user>());
runTest<internal::natural_join_t<DerivedUser>>(natural_join<derived_user>());

STATIC_REQUIRE(refers_to_recordset_callable<derived_user>);
STATIC_REQUIRE(refers_to_table_callable<derived_user>);
Expand Down