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

Commit

Permalink
Unified serialization and iteration of joins
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Mar 13, 2023
1 parent cd04472 commit 4adda95
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 222 deletions.
44 changes: 7 additions & 37 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,13 @@ namespace sqlite_orm {
}
};

template<class T, class O>
struct ast_iterator<left_join_t<T, O>, void> {
using node_type = left_join_t<T, O>;
template<class Join>
struct ast_iterator<Join, match_if<is_constrained_join, Join>> {
using node_type = Join;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
void operator()(const node_type& join, L& lambda) const {
iterate_ast(join.constraint, lambda);
}
};

Expand All @@ -512,8 +512,8 @@ namespace sqlite_orm {
using node_type = on_t<T>;

template<class L>
void operator()(const node_type& o, L& lambda) const {
iterate_ast(o.arg, lambda);
void operator()(const node_type& on, L& lambda) const {
iterate_ast(on.arg, lambda);
}
};

Expand All @@ -529,36 +529,6 @@ namespace sqlite_orm {
}
};

template<class T, class O>
struct ast_iterator<join_t<T, O>, void> {
using node_type = join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class T, class O>
struct ast_iterator<left_outer_join_t<T, O>, void> {
using node_type = left_outer_join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class T, class O>
struct ast_iterator<inner_join_t<T, O>, void> {
using node_type = inner_join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class R, class T, class E, class... Args>
struct ast_iterator<simple_case_t<R, T, E, Args...>, void> {
using node_type = simple_case_t<R, T, E, Args...>;
Expand Down
93 changes: 19 additions & 74 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1829,30 +1829,33 @@ namespace sqlite_orm {
}
};

template<class O>
struct statement_serializer<cross_join_t<O>, void> {
using statement_type = cross_join_t<O>;
template<class Join>
struct statement_serializer<
Join,
std::enable_if_t<polyfill::disjunction_v<polyfill::is_specialization_of<Join, cross_join_t>,
polyfill::is_specialization_of<Join, natural_join_t>>>> {
using statement_type = Join;

template<class Ctx>
std::string operator()(const statement_type& c, const Ctx& context) const {
std::string operator()(const statement_type& join, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(c) << " "
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
ss << static_cast<std::string>(join) << " "
<< streaming_identifier(lookup_table_name<type_t<Join>>(context.db_objects));
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<inner_join_t<T, O>, void> {
using statement_type = inner_join_t<T, O>;
template<class Join>
struct statement_serializer<Join, match_if<is_constrained_join, Join>> {
using statement_type = Join;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::string operator()(const statement_type& join, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
ss << static_cast<std::string>(join) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<type_t<Join>>>(context.db_objects),
alias_extractor<type_t<Join>>::as_alias())
<< " " << serialize(join.constraint, context);
return ss.str();
}
};
Expand All @@ -1862,69 +1865,11 @@ namespace sqlite_orm {
using statement_type = on_t<T>;

template<class Ctx>
std::string operator()(const statement_type& t, const Ctx& context) const {
std::string operator()(const statement_type& on, const Ctx& context) const {
std::stringstream ss;
auto newContext = context;
newContext.skip_table_name = false;
ss << static_cast<std::string>(t) << " " << serialize(t.arg, newContext) << " ";
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<join_t<T, O>, void> {
using statement_type = join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<left_join_t<T, O>, void> {
using statement_type = left_join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<left_outer_join_t<T, O>, void> {
using statement_type = left_outer_join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class O>
struct statement_serializer<natural_join_t<O>, void> {
using statement_type = natural_join_t<O>;

template<class Ctx>
std::string operator()(const statement_type& c, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(c) << " "
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
ss << static_cast<std::string>(on) << " " << serialize(on.arg, newContext) << " ";
return ss.str();
}
};
Expand Down
137 changes: 26 additions & 111 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12887,13 +12887,13 @@ namespace sqlite_orm {
}
};

template<class T, class O>
struct ast_iterator<left_join_t<T, O>, void> {
using node_type = left_join_t<T, O>;
template<class Join>
struct ast_iterator<Join, match_if<is_constrained_join, Join>> {
using node_type = Join;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
void operator()(const node_type& join, L& lambda) const {
iterate_ast(join.constraint, lambda);
}
};

Expand All @@ -12902,8 +12902,8 @@ namespace sqlite_orm {
using node_type = on_t<T>;

template<class L>
void operator()(const node_type& o, L& lambda) const {
iterate_ast(o.arg, lambda);
void operator()(const node_type& on, L& lambda) const {
iterate_ast(on.arg, lambda);
}
};

Expand All @@ -12919,36 +12919,6 @@ namespace sqlite_orm {
}
};

template<class T, class O>
struct ast_iterator<join_t<T, O>, void> {
using node_type = join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class T, class O>
struct ast_iterator<left_outer_join_t<T, O>, void> {
using node_type = left_outer_join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class T, class O>
struct ast_iterator<inner_join_t<T, O>, void> {
using node_type = inner_join_t<T, O>;

template<class L>
void operator()(const node_type& j, L& lambda) const {
iterate_ast(j.constraint, lambda);
}
};

template<class R, class T, class E, class... Args>
struct ast_iterator<simple_case_t<R, T, E, Args...>, void> {
using node_type = simple_case_t<R, T, E, Args...>;
Expand Down Expand Up @@ -17288,30 +17258,33 @@ namespace sqlite_orm {
}
};

template<class O>
struct statement_serializer<cross_join_t<O>, void> {
using statement_type = cross_join_t<O>;
template<class Join>
struct statement_serializer<
Join,
std::enable_if_t<polyfill::disjunction_v<polyfill::is_specialization_of<Join, cross_join_t>,
polyfill::is_specialization_of<Join, natural_join_t>>>> {
using statement_type = Join;

template<class Ctx>
std::string operator()(const statement_type& c, const Ctx& context) const {
std::string operator()(const statement_type& join, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(c) << " "
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
ss << static_cast<std::string>(join) << " "
<< streaming_identifier(lookup_table_name<type_t<Join>>(context.db_objects));
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<inner_join_t<T, O>, void> {
using statement_type = inner_join_t<T, O>;
template<class Join>
struct statement_serializer<Join, match_if<is_constrained_join, Join>> {
using statement_type = Join;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::string operator()(const statement_type& join, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
ss << static_cast<std::string>(join) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<type_t<Join>>>(context.db_objects),
alias_extractor<type_t<Join>>::as_alias())
<< " " << serialize(join.constraint, context);
return ss.str();
}
};
Expand All @@ -17321,69 +17294,11 @@ namespace sqlite_orm {
using statement_type = on_t<T>;

template<class Ctx>
std::string operator()(const statement_type& t, const Ctx& context) const {
std::string operator()(const statement_type& on, const Ctx& context) const {
std::stringstream ss;
auto newContext = context;
newContext.skip_table_name = false;
ss << static_cast<std::string>(t) << " " << serialize(t.arg, newContext) << " ";
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<join_t<T, O>, void> {
using statement_type = join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<left_join_t<T, O>, void> {
using statement_type = left_join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class T, class O>
struct statement_serializer<left_outer_join_t<T, O>, void> {
using statement_type = left_outer_join_t<T, O>;

template<class Ctx>
std::string operator()(const statement_type& l, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(l) << " "
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
alias_extractor<T>::as_alias())
<< " " << serialize(l.constraint, context);
return ss.str();
}
};

template<class O>
struct statement_serializer<natural_join_t<O>, void> {
using statement_type = natural_join_t<O>;

template<class Ctx>
std::string operator()(const statement_type& c, const Ctx& context) const {
std::stringstream ss;
ss << static_cast<std::string>(c) << " "
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
ss << static_cast<std::string>(on) << " " << serialize(on.arg, newContext) << " ";
return ss.str();
}
};
Expand Down

0 comments on commit 4adda95

Please sign in to comment.