Skip to content

Commit 4adda95

Browse files
committed
Unified serialization and iteration of joins
1 parent cd04472 commit 4adda95

File tree

3 files changed

+52
-222
lines changed

3 files changed

+52
-222
lines changed

dev/ast_iterator.h

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,13 @@ namespace sqlite_orm {
497497
}
498498
};
499499

500-
template<class T, class O>
501-
struct ast_iterator<left_join_t<T, O>, void> {
502-
using node_type = left_join_t<T, O>;
500+
template<class Join>
501+
struct ast_iterator<Join, match_if<is_constrained_join, Join>> {
502+
using node_type = Join;
503503

504504
template<class L>
505-
void operator()(const node_type& j, L& lambda) const {
506-
iterate_ast(j.constraint, lambda);
505+
void operator()(const node_type& join, L& lambda) const {
506+
iterate_ast(join.constraint, lambda);
507507
}
508508
};
509509

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

514514
template<class L>
515-
void operator()(const node_type& o, L& lambda) const {
516-
iterate_ast(o.arg, lambda);
515+
void operator()(const node_type& on, L& lambda) const {
516+
iterate_ast(on.arg, lambda);
517517
}
518518
};
519519

@@ -529,36 +529,6 @@ namespace sqlite_orm {
529529
}
530530
};
531531

532-
template<class T, class O>
533-
struct ast_iterator<join_t<T, O>, void> {
534-
using node_type = join_t<T, O>;
535-
536-
template<class L>
537-
void operator()(const node_type& j, L& lambda) const {
538-
iterate_ast(j.constraint, lambda);
539-
}
540-
};
541-
542-
template<class T, class O>
543-
struct ast_iterator<left_outer_join_t<T, O>, void> {
544-
using node_type = left_outer_join_t<T, O>;
545-
546-
template<class L>
547-
void operator()(const node_type& j, L& lambda) const {
548-
iterate_ast(j.constraint, lambda);
549-
}
550-
};
551-
552-
template<class T, class O>
553-
struct ast_iterator<inner_join_t<T, O>, void> {
554-
using node_type = inner_join_t<T, O>;
555-
556-
template<class L>
557-
void operator()(const node_type& j, L& lambda) const {
558-
iterate_ast(j.constraint, lambda);
559-
}
560-
};
561-
562532
template<class R, class T, class E, class... Args>
563533
struct ast_iterator<simple_case_t<R, T, E, Args...>, void> {
564534
using node_type = simple_case_t<R, T, E, Args...>;

dev/statement_serializer.h

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,30 +1829,33 @@ namespace sqlite_orm {
18291829
}
18301830
};
18311831

1832-
template<class O>
1833-
struct statement_serializer<cross_join_t<O>, void> {
1834-
using statement_type = cross_join_t<O>;
1832+
template<class Join>
1833+
struct statement_serializer<
1834+
Join,
1835+
std::enable_if_t<polyfill::disjunction_v<polyfill::is_specialization_of<Join, cross_join_t>,
1836+
polyfill::is_specialization_of<Join, natural_join_t>>>> {
1837+
using statement_type = Join;
18351838

18361839
template<class Ctx>
1837-
std::string operator()(const statement_type& c, const Ctx& context) const {
1840+
std::string operator()(const statement_type& join, const Ctx& context) const {
18381841
std::stringstream ss;
1839-
ss << static_cast<std::string>(c) << " "
1840-
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
1842+
ss << static_cast<std::string>(join) << " "
1843+
<< streaming_identifier(lookup_table_name<type_t<Join>>(context.db_objects));
18411844
return ss.str();
18421845
}
18431846
};
18441847

1845-
template<class T, class O>
1846-
struct statement_serializer<inner_join_t<T, O>, void> {
1847-
using statement_type = inner_join_t<T, O>;
1848+
template<class Join>
1849+
struct statement_serializer<Join, match_if<is_constrained_join, Join>> {
1850+
using statement_type = Join;
18481851

18491852
template<class Ctx>
1850-
std::string operator()(const statement_type& l, const Ctx& context) const {
1853+
std::string operator()(const statement_type& join, const Ctx& context) const {
18511854
std::stringstream ss;
1852-
ss << static_cast<std::string>(l) << " "
1853-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
1854-
alias_extractor<T>::as_alias())
1855-
<< " " << serialize(l.constraint, context);
1855+
ss << static_cast<std::string>(join) << " "
1856+
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<type_t<Join>>>(context.db_objects),
1857+
alias_extractor<type_t<Join>>::as_alias())
1858+
<< " " << serialize(join.constraint, context);
18561859
return ss.str();
18571860
}
18581861
};
@@ -1862,69 +1865,11 @@ namespace sqlite_orm {
18621865
using statement_type = on_t<T>;
18631866

18641867
template<class Ctx>
1865-
std::string operator()(const statement_type& t, const Ctx& context) const {
1868+
std::string operator()(const statement_type& on, const Ctx& context) const {
18661869
std::stringstream ss;
18671870
auto newContext = context;
18681871
newContext.skip_table_name = false;
1869-
ss << static_cast<std::string>(t) << " " << serialize(t.arg, newContext) << " ";
1870-
return ss.str();
1871-
}
1872-
};
1873-
1874-
template<class T, class O>
1875-
struct statement_serializer<join_t<T, O>, void> {
1876-
using statement_type = join_t<T, O>;
1877-
1878-
template<class Ctx>
1879-
std::string operator()(const statement_type& l, const Ctx& context) const {
1880-
std::stringstream ss;
1881-
ss << static_cast<std::string>(l) << " "
1882-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
1883-
alias_extractor<T>::as_alias())
1884-
<< " " << serialize(l.constraint, context);
1885-
return ss.str();
1886-
}
1887-
};
1888-
1889-
template<class T, class O>
1890-
struct statement_serializer<left_join_t<T, O>, void> {
1891-
using statement_type = left_join_t<T, O>;
1892-
1893-
template<class Ctx>
1894-
std::string operator()(const statement_type& l, const Ctx& context) const {
1895-
std::stringstream ss;
1896-
ss << static_cast<std::string>(l) << " "
1897-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
1898-
alias_extractor<T>::as_alias())
1899-
<< " " << serialize(l.constraint, context);
1900-
return ss.str();
1901-
}
1902-
};
1903-
1904-
template<class T, class O>
1905-
struct statement_serializer<left_outer_join_t<T, O>, void> {
1906-
using statement_type = left_outer_join_t<T, O>;
1907-
1908-
template<class Ctx>
1909-
std::string operator()(const statement_type& l, const Ctx& context) const {
1910-
std::stringstream ss;
1911-
ss << static_cast<std::string>(l) << " "
1912-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
1913-
alias_extractor<T>::as_alias())
1914-
<< " " << serialize(l.constraint, context);
1915-
return ss.str();
1916-
}
1917-
};
1918-
1919-
template<class O>
1920-
struct statement_serializer<natural_join_t<O>, void> {
1921-
using statement_type = natural_join_t<O>;
1922-
1923-
template<class Ctx>
1924-
std::string operator()(const statement_type& c, const Ctx& context) const {
1925-
std::stringstream ss;
1926-
ss << static_cast<std::string>(c) << " "
1927-
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
1872+
ss << static_cast<std::string>(on) << " " << serialize(on.arg, newContext) << " ";
19281873
return ss.str();
19291874
}
19301875
};

include/sqlite_orm/sqlite_orm.h

Lines changed: 26 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -12887,13 +12887,13 @@ namespace sqlite_orm {
1288712887
}
1288812888
};
1288912889

12890-
template<class T, class O>
12891-
struct ast_iterator<left_join_t<T, O>, void> {
12892-
using node_type = left_join_t<T, O>;
12890+
template<class Join>
12891+
struct ast_iterator<Join, match_if<is_constrained_join, Join>> {
12892+
using node_type = Join;
1289312893

1289412894
template<class L>
12895-
void operator()(const node_type& j, L& lambda) const {
12896-
iterate_ast(j.constraint, lambda);
12895+
void operator()(const node_type& join, L& lambda) const {
12896+
iterate_ast(join.constraint, lambda);
1289712897
}
1289812898
};
1289912899

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

1290412904
template<class L>
12905-
void operator()(const node_type& o, L& lambda) const {
12906-
iterate_ast(o.arg, lambda);
12905+
void operator()(const node_type& on, L& lambda) const {
12906+
iterate_ast(on.arg, lambda);
1290712907
}
1290812908
};
1290912909

@@ -12919,36 +12919,6 @@ namespace sqlite_orm {
1291912919
}
1292012920
};
1292112921

12922-
template<class T, class O>
12923-
struct ast_iterator<join_t<T, O>, void> {
12924-
using node_type = join_t<T, O>;
12925-
12926-
template<class L>
12927-
void operator()(const node_type& j, L& lambda) const {
12928-
iterate_ast(j.constraint, lambda);
12929-
}
12930-
};
12931-
12932-
template<class T, class O>
12933-
struct ast_iterator<left_outer_join_t<T, O>, void> {
12934-
using node_type = left_outer_join_t<T, O>;
12935-
12936-
template<class L>
12937-
void operator()(const node_type& j, L& lambda) const {
12938-
iterate_ast(j.constraint, lambda);
12939-
}
12940-
};
12941-
12942-
template<class T, class O>
12943-
struct ast_iterator<inner_join_t<T, O>, void> {
12944-
using node_type = inner_join_t<T, O>;
12945-
12946-
template<class L>
12947-
void operator()(const node_type& j, L& lambda) const {
12948-
iterate_ast(j.constraint, lambda);
12949-
}
12950-
};
12951-
1295212922
template<class R, class T, class E, class... Args>
1295312923
struct ast_iterator<simple_case_t<R, T, E, Args...>, void> {
1295412924
using node_type = simple_case_t<R, T, E, Args...>;
@@ -17288,30 +17258,33 @@ namespace sqlite_orm {
1728817258
}
1728917259
};
1729017260

17291-
template<class O>
17292-
struct statement_serializer<cross_join_t<O>, void> {
17293-
using statement_type = cross_join_t<O>;
17261+
template<class Join>
17262+
struct statement_serializer<
17263+
Join,
17264+
std::enable_if_t<polyfill::disjunction_v<polyfill::is_specialization_of<Join, cross_join_t>,
17265+
polyfill::is_specialization_of<Join, natural_join_t>>>> {
17266+
using statement_type = Join;
1729417267

1729517268
template<class Ctx>
17296-
std::string operator()(const statement_type& c, const Ctx& context) const {
17269+
std::string operator()(const statement_type& join, const Ctx& context) const {
1729717270
std::stringstream ss;
17298-
ss << static_cast<std::string>(c) << " "
17299-
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
17271+
ss << static_cast<std::string>(join) << " "
17272+
<< streaming_identifier(lookup_table_name<type_t<Join>>(context.db_objects));
1730017273
return ss.str();
1730117274
}
1730217275
};
1730317276

17304-
template<class T, class O>
17305-
struct statement_serializer<inner_join_t<T, O>, void> {
17306-
using statement_type = inner_join_t<T, O>;
17277+
template<class Join>
17278+
struct statement_serializer<Join, match_if<is_constrained_join, Join>> {
17279+
using statement_type = Join;
1730717280

1730817281
template<class Ctx>
17309-
std::string operator()(const statement_type& l, const Ctx& context) const {
17282+
std::string operator()(const statement_type& join, const Ctx& context) const {
1731017283
std::stringstream ss;
17311-
ss << static_cast<std::string>(l) << " "
17312-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
17313-
alias_extractor<T>::as_alias())
17314-
<< " " << serialize(l.constraint, context);
17284+
ss << static_cast<std::string>(join) << " "
17285+
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<type_t<Join>>>(context.db_objects),
17286+
alias_extractor<type_t<Join>>::as_alias())
17287+
<< " " << serialize(join.constraint, context);
1731517288
return ss.str();
1731617289
}
1731717290
};
@@ -17321,69 +17294,11 @@ namespace sqlite_orm {
1732117294
using statement_type = on_t<T>;
1732217295

1732317296
template<class Ctx>
17324-
std::string operator()(const statement_type& t, const Ctx& context) const {
17297+
std::string operator()(const statement_type& on, const Ctx& context) const {
1732517298
std::stringstream ss;
1732617299
auto newContext = context;
1732717300
newContext.skip_table_name = false;
17328-
ss << static_cast<std::string>(t) << " " << serialize(t.arg, newContext) << " ";
17329-
return ss.str();
17330-
}
17331-
};
17332-
17333-
template<class T, class O>
17334-
struct statement_serializer<join_t<T, O>, void> {
17335-
using statement_type = join_t<T, O>;
17336-
17337-
template<class Ctx>
17338-
std::string operator()(const statement_type& l, const Ctx& context) const {
17339-
std::stringstream ss;
17340-
ss << static_cast<std::string>(l) << " "
17341-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
17342-
alias_extractor<T>::as_alias())
17343-
<< " " << serialize(l.constraint, context);
17344-
return ss.str();
17345-
}
17346-
};
17347-
17348-
template<class T, class O>
17349-
struct statement_serializer<left_join_t<T, O>, void> {
17350-
using statement_type = left_join_t<T, O>;
17351-
17352-
template<class Ctx>
17353-
std::string operator()(const statement_type& l, const Ctx& context) const {
17354-
std::stringstream ss;
17355-
ss << static_cast<std::string>(l) << " "
17356-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
17357-
alias_extractor<T>::as_alias())
17358-
<< " " << serialize(l.constraint, context);
17359-
return ss.str();
17360-
}
17361-
};
17362-
17363-
template<class T, class O>
17364-
struct statement_serializer<left_outer_join_t<T, O>, void> {
17365-
using statement_type = left_outer_join_t<T, O>;
17366-
17367-
template<class Ctx>
17368-
std::string operator()(const statement_type& l, const Ctx& context) const {
17369-
std::stringstream ss;
17370-
ss << static_cast<std::string>(l) << " "
17371-
<< streaming_identifier(lookup_table_name<mapped_type_proxy_t<T>>(context.db_objects),
17372-
alias_extractor<T>::as_alias())
17373-
<< " " << serialize(l.constraint, context);
17374-
return ss.str();
17375-
}
17376-
};
17377-
17378-
template<class O>
17379-
struct statement_serializer<natural_join_t<O>, void> {
17380-
using statement_type = natural_join_t<O>;
17381-
17382-
template<class Ctx>
17383-
std::string operator()(const statement_type& c, const Ctx& context) const {
17384-
std::stringstream ss;
17385-
ss << static_cast<std::string>(c) << " "
17386-
<< streaming_identifier(lookup_table_name<O>(context.db_objects));
17301+
ss << static_cast<std::string>(on) << " " << serialize(on.arg, newContext) << " ";
1738717302
return ss.str();
1738817303
}
1738917304
};

0 commit comments

Comments
 (0)