Skip to content

Commit 17f861f

Browse files
committed
Generalized serializer context
* Removed `serializer_context_builder`, which is now entirely replaced by `obtain_db_objects()`. * Renamed serializer context flag variables.
1 parent d3ab62a commit 17f861f

File tree

16 files changed

+76
-108
lines changed

16 files changed

+76
-108
lines changed

dev/ast/set.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace sqlite_orm {
5151
template<class L, class R>
5252
void push_back(assign_t<L, R> assign) {
5353
auto newContext = this->context;
54-
newContext.skip_table_name = true;
54+
newContext.omit_table_name = true;
5555
// note: we are only interested in the table name on the left-hand side of the assignment operator expression
5656
iterate_ast(assign.lhs, this->collector);
5757
std::stringstream ss;
@@ -108,7 +108,6 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
108108
*/
109109
template<class S>
110110
internal::dynamic_set_t<internal::serializer_context<typename S::db_objects_type>> dynamic_set(const S& storage) {
111-
internal::serializer_context_builder<S> builder(storage);
112-
return builder();
111+
return {obtain_db_objects(storage)};
113112
}
114113
}

dev/column_names_getter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace sqlite_orm {
3333
if (definedOrder) {
3434
auto& table = pick_table<mapped_type_proxy_t<T>>(context.db_objects);
3535
collectedExpressions.reserve(collectedExpressions.size() + table.template count_of<is_column>());
36-
table.for_each_column([qualified = !context.skip_table_name,
36+
table.for_each_column([qualified = !context.omit_table_name,
3737
&tableName = table.name,
3838
&collectedExpressions](const column_identifier& column) {
3939
if constexpr (is_alias<T>::value) {
@@ -50,7 +50,7 @@ namespace sqlite_orm {
5050
collectedExpressions.reserve(collectedExpressions.size() + 1);
5151
if constexpr (is_alias<T>::value) {
5252
collectedExpressions.push_back(quote_identifier(alias_extractor<T>::extract()) + ".*");
53-
} else if (!context.skip_table_name) {
53+
} else if (!context.omit_table_name) {
5454
const basic_table& table = pick_table<mapped_type_proxy_t<T>>(context.db_objects);
5555
collectedExpressions.push_back(quote_identifier(table.name) + ".*");
5656
} else {

dev/conditions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ namespace sqlite_orm {
493493
template<class O>
494494
void push_back(order_by_t<O> orderBy) {
495495
auto newContext = this->context;
496-
newContext.skip_table_name = false;
496+
newContext.omit_table_name = false;
497497
auto columnName = serialize(orderBy._expression, newContext);
498498
this->entries.emplace_back(std::move(columnName), std::move(orderBy._collate_argument), orderBy._order);
499499
}
@@ -1149,8 +1149,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
11491149
template<class S>
11501150
internal::dynamic_order_by_t<internal::serializer_context<typename S::db_objects_type>>
11511151
dynamic_order_by(const S& storage) {
1152-
internal::serializer_context_builder<S> builder(storage);
1153-
return builder();
1152+
return {obtain_db_objects(storage)};
11541153
}
11551154

11561155
/**

dev/cte_column_names_collector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace sqlite_orm {
5757
SQLITE_ORM_STATIC_CALLOP std::vector<std::string>
5858
operator()(const expression_type& t, const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
5959
auto newContext = context;
60-
newContext.skip_table_name = true;
60+
newContext.omit_table_name = true;
6161
std::string columnName = serialize(t, newContext);
6262
if (columnName.empty()) {
6363
throw std::system_error{orm_error_code::column_not_found};
@@ -137,7 +137,7 @@ namespace sqlite_orm {
137137
std::vector<std::string> columnNames;
138138
columnNames.reserve(size_t(cols.count));
139139
auto newContext = context;
140-
newContext.skip_table_name = true;
140+
newContext.omit_table_name = true;
141141
iterate_tuple(cols.columns, [&columnNames, &newContext](auto& m) {
142142
using value_type = polyfill::remove_cvref_t<decltype(m)>;
143143

dev/mapped_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace sqlite_orm {
4242

4343
auto& dbObjects = obtain_db_objects(this->storage);
4444
context_t context{dbObjects};
45-
context.skip_table_name = false;
45+
context.omit_table_name = false;
4646
context.replace_bindable_with_question = true;
4747

4848
const std::string sql = serialize(this->expression, context);

dev/order_by_serializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace sqlite_orm {
4545
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
4646
std::stringstream ss;
4747
auto newContext = context;
48-
newContext.skip_table_name = false;
48+
newContext.omit_table_name = false;
4949

5050
ss << serialize(orderBy._expression, newContext);
5151
seralize_collate(ss, orderBy);

dev/result_set_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace sqlite_orm::internal {
5353
using context_t = serializer_context<ExprDBOs>;
5454

5555
context_t context{exprDBOs};
56-
context.skip_table_name = false;
56+
context.omit_table_name = false;
5757
context.replace_bindable_with_question = true;
5858

5959
const std::string sql = serialize(this->expression, context);

dev/serializer_context.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace sqlite_orm {
66

77
struct serializer_context_base {
88
bool replace_bindable_with_question = false;
9-
bool skip_table_name = true;
9+
bool omit_table_name = true;
1010
bool use_parentheses = true;
11-
bool fts5_columns = false;
11+
bool omit_column_type = false;
1212
};
1313

1414
template<class DBOs>
@@ -19,20 +19,6 @@ namespace sqlite_orm {
1919

2020
serializer_context(const db_objects_type& dbObjects) : db_objects{dbObjects} {}
2121
};
22-
23-
template<class S>
24-
struct serializer_context_builder {
25-
using storage_type = S;
26-
using db_objects_type = typename storage_type::db_objects_type;
27-
28-
serializer_context_builder(const storage_type& storage_) : storage{storage_} {}
29-
30-
serializer_context<db_objects_type> operator()() const {
31-
return {obtain_db_objects(this->storage)};
32-
}
33-
34-
const storage_type& storage;
35-
};
3622
}
3723

3824
}

dev/serializing_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ namespace sqlite_orm {
433433
ss << ' ' << serialize(constraint, context);
434434
});
435435
// add implicit null constraint
436-
if (!context.fts5_columns) {
436+
if (!context.omit_column_type) {
437437
constexpr bool hasExplicitNullableConstraint =
438438
mpl::invoke_t<mpl::disjunction<check_if_has_type<null_t>, check_if_has_type<not_null_t>>,
439439
constraints_tuple>::value;

dev/statement_serializer.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ namespace sqlite_orm {
420420
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& c,
421421
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
422422
std::stringstream ss;
423-
if (!context.skip_table_name) {
423+
if (!context.omit_table_name) {
424424
ss << streaming_identifier(alias_extractor<T>::extract()) << ".";
425425
}
426426
auto newContext = context;
427-
newContext.skip_table_name = true;
427+
newContext.omit_table_name = true;
428428
ss << serialize(c.column, newContext);
429429
return ss.str();
430430
}
@@ -442,7 +442,7 @@ namespace sqlite_orm {
442442
std::stringstream ss;
443443
if (auto* columnName = find_column_name(context.db_objects, e)) {
444444
ss << streaming_identifier(
445-
!context.skip_table_name ? lookup_table_name<table_type_of_t<E>>(context.db_objects) : "",
445+
!context.omit_table_name ? lookup_table_name<table_type_of_t<E>>(context.db_objects) : "",
446446
*columnName,
447447
"");
448448
} else {
@@ -504,7 +504,7 @@ namespace sqlite_orm {
504504
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
505505
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
506506
std::stringstream ss;
507-
if (!context.skip_table_name) {
507+
if (!context.omit_table_name) {
508508
ss << streaming_identifier(lookup_table_name<O>(context.db_objects)) << ".";
509509
}
510510
ss << static_cast<std::string>(statement);
@@ -520,7 +520,7 @@ namespace sqlite_orm {
520520
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
521521
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
522522
std::stringstream ss;
523-
if (!context.skip_table_name) {
523+
if (!context.omit_table_name) {
524524
ss << streaming_identifier(lookup_table_name<O>(context.db_objects)) << ".";
525525
}
526526
ss << static_cast<std::string>(statement);
@@ -536,7 +536,7 @@ namespace sqlite_orm {
536536
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
537537
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
538538
std::stringstream ss;
539-
if (!context.skip_table_name) {
539+
if (!context.omit_table_name) {
540540
ss << streaming_identifier(lookup_table_name<O>(context.db_objects)) << ".";
541541
}
542542
ss << static_cast<std::string>(statement);
@@ -1305,7 +1305,7 @@ namespace sqlite_orm {
13051305
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
13061306
std::stringstream ss;
13071307
ss << streaming_identifier(column.name);
1308-
if (!context.fts5_columns) {
1308+
if (!context.omit_column_type) {
13091309
ss << " " << type_printer<field_type_t<column_field<G, S>>>().print();
13101310
}
13111311
ss << streaming_column_constraints(
@@ -1452,7 +1452,7 @@ namespace sqlite_orm {
14521452
std::stringstream ss;
14531453
ss << "SET ";
14541454
auto leftContext = context;
1455-
leftContext.skip_table_name = true;
1455+
leftContext.omit_table_name = true;
14561456
iterate_tuple(statement.assigns, [&ss, &context, &leftContext, first = true](auto& value) mutable {
14571457
static constexpr std::array<orm_gsl::czstring, 2> sep = {", ", ""};
14581458
ss << sep[std::exchange(first, false)] << serialize(value.lhs, leftContext) << ' '
@@ -1612,7 +1612,7 @@ namespace sqlite_orm {
16121612
ss << ' ';
16131613
if constexpr (is_columns<value_type>::value) {
16141614
auto newContext = context;
1615-
newContext.skip_table_name = true;
1615+
newContext.omit_table_name = true;
16161616
newContext.use_parentheses = true;
16171617
ss << serialize(value, newContext);
16181618
} else if constexpr (is_values<value_type>::value || is_select<value_type>::value) {
@@ -1877,7 +1877,7 @@ namespace sqlite_orm {
18771877
template<class Ctx>
18781878
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& sel,
18791879
Ctx context) SQLITE_ORM_OR_CONST_CALLOP {
1880-
context.skip_table_name = false;
1880+
context.omit_table_name = false;
18811881
// subqueries should always use parentheses in column names
18821882
auto subCtx = context;
18831883
subCtx.use_parentheses = true;
@@ -1961,7 +1961,7 @@ namespace sqlite_orm {
19611961
std::stringstream ss;
19621962
ss << "USING FTS5(";
19631963
auto subContext = context;
1964-
subContext.fts5_columns = true;
1964+
subContext.omit_column_type = true;
19651965
ss << streaming_expressions_tuple(statement.columns, subContext) << ")";
19661966
return ss.str();
19671967
}
@@ -2051,7 +2051,7 @@ namespace sqlite_orm {
20512051
std::stringstream ss;
20522052
ss << "OLD.";
20532053
auto newContext = context;
2054-
newContext.skip_table_name = true;
2054+
newContext.omit_table_name = true;
20552055
ss << serialize(statement.expression, newContext);
20562056
return ss.str();
20572057
}
@@ -2067,7 +2067,7 @@ namespace sqlite_orm {
20672067
std::stringstream ss;
20682068
ss << "NEW.";
20692069
auto newContext = context;
2070-
newContext.skip_table_name = true;
2070+
newContext.omit_table_name = true;
20712071
ss << serialize(statement.expression, newContext);
20722072
return ss.str();
20732073
}
@@ -2310,7 +2310,7 @@ namespace sqlite_orm {
23102310
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
23112311
std::stringstream ss;
23122312
auto newContext = context;
2313-
newContext.skip_table_name = false;
2313+
newContext.omit_table_name = false;
23142314
ss << static_cast<std::string>(on) << " " << serialize(on.arg, newContext) << " ";
23152315
return ss.str();
23162316
}
@@ -2325,7 +2325,7 @@ namespace sqlite_orm {
23252325
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
23262326
std::stringstream ss;
23272327
auto newContext = context;
2328-
newContext.skip_table_name = false;
2328+
newContext.omit_table_name = false;
23292329
ss << "GROUP BY " << streaming_expressions_tuple(statement.args, newContext) << " HAVING "
23302330
<< serialize(statement.expression, context);
23312331
return ss.str();
@@ -2341,7 +2341,7 @@ namespace sqlite_orm {
23412341
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
23422342
std::stringstream ss;
23432343
auto newContext = context;
2344-
newContext.skip_table_name = false;
2344+
newContext.omit_table_name = false;
23452345
ss << "GROUP BY " << streaming_expressions_tuple(statement.args, newContext);
23462346
return ss.str();
23472347
}
@@ -2359,7 +2359,7 @@ namespace sqlite_orm {
23592359
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
23602360
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
23612361
auto newContext = context;
2362-
newContext.skip_table_name = false;
2362+
newContext.omit_table_name = false;
23632363
std::stringstream ss;
23642364
ss << "LIMIT ";
23652365
if constexpr (HO) {
@@ -2401,7 +2401,7 @@ namespace sqlite_orm {
24012401
SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& statement,
24022402
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
24032403
auto newContext = context;
2404-
newContext.skip_table_name = true;
2404+
newContext.omit_table_name = true;
24052405
return static_cast<std::string>(statement) + " (" + serialize(statement.column, newContext) + ")";
24062406
}
24072407
};

0 commit comments

Comments
 (0)