Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Added a few unit tests for table_name_collector
Browse files Browse the repository at this point in the history
* Also made `aliased_column()` work with column pointers
  • Loading branch information
trueqbit committed Feb 5, 2023
1 parent c1fc706 commit 2521716
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 171 deletions.
11 changes: 7 additions & 4 deletions dev/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <sstream> // std::stringstream
#include <string> // std::string

#include "type_traits.h"

namespace sqlite_orm {

/**
Expand Down Expand Up @@ -86,10 +88,11 @@ namespace sqlite_orm {
* @return column with table alias attached. Place it instead of a column statement in case you need to specify a
* column with table alias prefix like 'a.column'. For more information please look through self_join.cpp example
*/
template<class T, class C>
internal::alias_column_t<T, C> alias_column(C c) {
static_assert(std::is_member_pointer<C>::value,
"alias_column argument must be a member pointer mapped to a storage");
template<class A, class C>
internal::alias_column_t<A, C> alias_column(C c) {
using table_type = internal::type_t<A>;
static_assert(std::is_same<internal::table_type_of_t<C>, table_type>::value,
"Column must be from aliased table");
return {c};
}

Expand Down
3 changes: 2 additions & 1 deletion dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <memory>
#include <array>
#include "functional/cxx_string_view.h"
#include "functional/cxx_optional.h"

#include "functional/cxx_universal.h"
#include "functional/cxx_functional_polyfill.h"
Expand Down Expand Up @@ -1076,7 +1077,7 @@ namespace sqlite_orm {
using statement_type = dynamic_set_t<C>;

template<class Ctx>
std::string operator()(const statement_type& statement, const Ctx& context) const {
std::string operator()(const statement_type& statement, const Ctx&) const {
std::stringstream ss;
ss << "SET ";
int index = 0;
Expand Down
9 changes: 6 additions & 3 deletions dev/table_name_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string> // std::string
#include <functional> // std::function
#include <typeindex> // std::type_index
#include <utility> // std::move

#include "functional/cxx_type_traits_polyfill.h"
#include "type_traits.h"
Expand Down Expand Up @@ -41,9 +42,11 @@ namespace sqlite_orm {
table_names.emplace(this->find_table_name(typeid(T)), "");
}

template<class T, class C>
void operator()(const alias_column_t<T, C>& a) const {
(*this)(a.column, alias_extractor<T>::get());
template<class A, class C>
void operator()(const alias_column_t<A, C>&) const {
// note: instead of accessing the column, we are interested in the type the column is aliased into
auto tableName = this->find_table_name(typeid(mapped_type_proxy_t<A>));
table_names.emplace(std::move(tableName), alias_extractor<A>::get());
}

template<class T>
Expand Down
5 changes: 3 additions & 2 deletions dev/table_type_of.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once

#include "indexed_column.h"

namespace sqlite_orm {

namespace internal {

template<class T, class F>
struct column_pointer;

template<class C>
struct indexed_column_t;

/**
* Trait class used to define table mapped type by setter/getter/member
* T - member pointer
Expand Down
Loading

0 comments on commit 2521716

Please sign in to comment.