Skip to content

Commit

Permalink
Merge pull request #10 from fnc12/dev-to-plus
Browse files Browse the repository at this point in the history
Dev to plus
  • Loading branch information
fnc12 committed Jul 2, 2022
2 parents 2761bc8 + 043bee1 commit c581a65
Show file tree
Hide file tree
Showing 73 changed files with 1,649 additions and 1,511 deletions.
13 changes: 5 additions & 8 deletions dev/alias.h
Expand Up @@ -39,7 +39,11 @@ namespace sqlite_orm {
};

template<class T, class SFINAE = void>
struct alias_extractor;
struct alias_extractor {
static std::string get() {
return {};
}
};

template<class T>
struct alias_extractor<T, std::enable_if_t<std::is_base_of<alias_tag, T>::value>> {
Expand All @@ -50,13 +54,6 @@ namespace sqlite_orm {
}
};

template<class T>
struct alias_extractor<T, std::enable_if_t<!std::is_base_of<alias_tag, T>::value>> {
static std::string get() {
return {};
}
};

/**
* Used to store alias for expression
*/
Expand Down
4 changes: 2 additions & 2 deletions dev/column.h
Expand Up @@ -23,7 +23,7 @@ namespace sqlite_orm {
/**
* Column name.
*/
const std::string name;
std::string name;
};

struct empty_setter {};
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace sqlite_orm {
using constraints_type = std::tuple<Op...>;

SQLITE_ORM_NOUNIQUEADDRESS
const constraints_type constraints;
constraints_type constraints;

/**
* Checks whether contraints are of trait `Trait`
Expand Down
43 changes: 28 additions & 15 deletions dev/column_names_getter.h
Expand Up @@ -8,6 +8,7 @@
#include "error_code.h"
#include "serializer_context.h"
#include "select_constraints.h"
#include "serializing_util.h"
#include "util.h"

namespace sqlite_orm {
Expand Down Expand Up @@ -40,6 +41,28 @@ namespace sqlite_orm {
return serializer(t, context);
}

template<class T, class Ctx>
std::vector<std::string> collect_table_column_names(bool definedOrder, const Ctx& context) {
if(definedOrder) {
std::vector<std::string> quotedNames;
auto& table = pick_table<mapped_type_proxy_t<T>>(context.db_objects);
quotedNames.reserve(table.count_columns_amount());
table.for_each_column([&quotedNames](const column_identifier& column) {
if(std::is_base_of<alias_tag, T>::value) {
quotedNames.push_back(quote_identifier(alias_extractor<T>::get()) + "." +
quote_identifier(column.name));
} else {
quotedNames.push_back(quote_identifier(column.name));
}
});
return quotedNames;
} else if(std::is_base_of<alias_tag, T>::value) {
return {quote_identifier(alias_extractor<T>::get()) + ".*"};
} else {
return {"*"};
}
}

template<class T>
struct column_names_getter<std::reference_wrapper<T>, void> {
using expression_type = std::reference_wrapper<T>;
Expand All @@ -51,22 +74,12 @@ namespace sqlite_orm {
};

template<class T>
struct column_names_getter<asterisk_t<T>, match_if_not<std::is_base_of, alias_tag, T>> {
struct column_names_getter<asterisk_t<T>> {
using expression_type = asterisk_t<T>;

template<class Ctx>
std::vector<std::string> operator()(const expression_type&, const Ctx&) const {
return {"*"};
}
};

template<class A>
struct column_names_getter<asterisk_t<A>, match_if<std::is_base_of, alias_tag, A>> {
using expression_type = asterisk_t<A>;

template<class Ctx>
std::vector<std::string> operator()(const expression_type&, const Ctx&) const {
return {quote_identifier(alias_extractor<A>::get()) + ".*"};
std::vector<std::string> operator()(const expression_type& expression, const Ctx& context) const {
return collect_table_column_names<T>(expression.defined_order, context);
}
};

Expand All @@ -75,8 +88,8 @@ namespace sqlite_orm {
using expression_type = object_t<T>;

template<class Ctx>
std::vector<std::string> operator()(const expression_type&, const Ctx&) const {
return {"*"};
std::vector<std::string> operator()(const expression_type& expression, const Ctx& context) const {
return collect_table_column_names<T>(expression.defined_order, context);
}
};

Expand Down

0 comments on commit c581a65

Please sign in to comment.