Skip to content

Commit 4997b7d

Browse files
committed
Use of a string_view for serialization in several places
1 parent 32fef04 commit 4997b7d

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed

dev/column_names_getter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace sqlite_orm {
2222
namespace internal {
2323

2424
template<class T, class C>
25-
std::string serialize(const T& t, const C& context);
25+
auto serialize(const T& t, const C& context);
2626

2727
template<class T, class Ctx>
2828
std::vector<std::string>& collect_table_column_names(std::vector<std::string>& collectedExpressions,

dev/cte_column_names_collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace sqlite_orm {
2121
namespace internal {
2222
// collecting column names utilizes the statement serializer
2323
template<class T, class C>
24-
std::string serialize(const T& t, const C& context);
24+
auto serialize(const T& t, const C& context);
2525

2626
inline void unquote_identifier(std::string& identifier) {
2727
if(!identifier.empty()) {

dev/default_value_extractor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace sqlite_orm {
1111
namespace internal {
1212

1313
template<class T, class C>
14-
std::string serialize(const T& t, const C& context);
14+
auto serialize(const T& t, const C& context);
1515

1616
/**
1717
* Serialize default value of a column's default valu

dev/serializing_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace sqlite_orm {
2121
struct order_by_t;
2222

2323
template<class T, class C>
24-
std::string serialize(const T& t, const C& context);
24+
auto serialize(const T& t, const C& context);
2525

2626
template<class T, class Ctx>
2727
std::string serialize_order_by(const T&, const Ctx&);

dev/statement_serializer.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "cte_column_names_collector.h"
4343
#include "order_by_serializer.h"
4444
#include "serializing_util.h"
45+
#include "serialize_result_type.h"
4546
#include "statement_binder.h"
4647
#include "values.h"
4748
#include "schema/triggers.h"
@@ -58,7 +59,7 @@ namespace sqlite_orm {
5859
struct statement_serializer;
5960

6061
template<class T, class C>
61-
std::string serialize(const T& t, const C& context) {
62+
auto serialize(const T& t, const C& context) {
6263
statement_serializer<T> serializer;
6364
return serializer(t, context);
6465
}
@@ -148,7 +149,7 @@ namespace sqlite_orm {
148149
}
149150

150151
template<class Ctx>
151-
std::string serialize(const statement_type& statement, const Ctx& context, const std::string& tableName) {
152+
auto serialize(const statement_type& statement, const Ctx& context, const std::string& tableName) {
152153
std::stringstream ss;
153154
ss << "CREATE TABLE " << streaming_identifier(tableName) << " ( "
154155
<< streaming_expressions_tuple(statement.elements, context) << ")";
@@ -426,7 +427,7 @@ namespace sqlite_orm {
426427
using statement_type = rank_t;
427428

428429
template<class Ctx>
429-
std::string operator()(const statement_type& /*statement*/, const Ctx&) const {
430+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx&) const {
430431
return "rank";
431432
}
432433
};
@@ -590,7 +591,7 @@ namespace sqlite_orm {
590591
using statement_type = materialized_t;
591592

592593
template<class Ctx>
593-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
594+
std::string_view operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
594595
return "MATERIALIZED";
595596
}
596597
};
@@ -600,7 +601,7 @@ namespace sqlite_orm {
600601
using statement_type = not_materialized_t;
601602

602603
template<class Ctx>
603-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
604+
std::string_view operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
604605
return "NOT MATERIALIZED";
605606
}
606607
};
@@ -950,7 +951,7 @@ namespace sqlite_orm {
950951
using statement_type = conflict_clause_t;
951952

952953
template<class Ctx>
953-
std::string operator()(const statement_type& statement, const Ctx&) const {
954+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
954955
switch(statement) {
955956
case conflict_clause_t::rollback:
956957
return "ROLLBACK";
@@ -982,7 +983,7 @@ namespace sqlite_orm {
982983
using statement_type = null_t;
983984

984985
template<class Ctx>
985-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
986+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
986987
return "NULL";
987988
}
988989
};
@@ -992,7 +993,7 @@ namespace sqlite_orm {
992993
using statement_type = not_null_t;
993994

994995
template<class Ctx>
995-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
996+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
996997
return "NOT NULL";
997998
}
998999
};
@@ -1630,7 +1631,7 @@ namespace sqlite_orm {
16301631
using statement_type = conflict_action;
16311632

16321633
template<class Ctx>
1633-
std::string operator()(const statement_type& statement, const Ctx&) const {
1634+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
16341635
switch(statement) {
16351636
case conflict_action::replace:
16361637
return "REPLACE";
@@ -1653,7 +1654,10 @@ namespace sqlite_orm {
16531654

16541655
template<class Ctx>
16551656
std::string operator()(const statement_type& statement, const Ctx& context) const {
1656-
return "OR " + serialize(statement.action, context);
1657+
std::stringstream ss;
1658+
1659+
ss << "OR " << serialize(statement.action, context);
1660+
return ss.str();
16571661
}
16581662
};
16591663

@@ -1888,7 +1892,7 @@ namespace sqlite_orm {
18881892
using statement_type = trigger_timing;
18891893

18901894
template<class Ctx>
1891-
std::string operator()(const statement_type& statement, const Ctx&) const {
1895+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
18921896
switch(statement) {
18931897
case trigger_timing::trigger_before:
18941898
return "BEFORE";
@@ -1906,7 +1910,7 @@ namespace sqlite_orm {
19061910
using statement_type = trigger_type;
19071911

19081912
template<class Ctx>
1909-
std::string operator()(const statement_type& statement, const Ctx&) const {
1913+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
19101914
switch(statement) {
19111915
case trigger_type::trigger_delete:
19121916
return "DELETE";
@@ -2157,7 +2161,7 @@ namespace sqlite_orm {
21572161
using statement_type = default_values_t;
21582162

21592163
template<class Ctx>
2160-
std::string operator()(const statement_type&, const Ctx&) const {
2164+
serialize_result_type operator()(const statement_type&, const Ctx&) const {
21612165
return "DEFAULT VALUES";
21622166
}
21632167
};

include/sqlite_orm/sqlite_orm.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11831,7 +11831,7 @@ namespace sqlite_orm {
1183111831
namespace internal {
1183211832

1183311833
template<class T, class C>
11834-
std::string serialize(const T& t, const C& context);
11834+
auto serialize(const T& t, const C& context);
1183511835

1183611836
/**
1183711837
* Serialize default value of a column's default valu
@@ -15282,7 +15282,7 @@ namespace sqlite_orm {
1528215282
struct order_by_t;
1528315283

1528415284
template<class T, class C>
15285-
std::string serialize(const T& t, const C& context);
15285+
auto serialize(const T& t, const C& context);
1528615286

1528715287
template<class T, class Ctx>
1528815288
std::string serialize_order_by(const T&, const Ctx&);
@@ -17710,7 +17710,7 @@ namespace sqlite_orm {
1771017710
namespace internal {
1771117711

1771217712
template<class T, class C>
17713-
std::string serialize(const T& t, const C& context);
17713+
auto serialize(const T& t, const C& context);
1771417714

1771517715
template<class T, class Ctx>
1771617716
std::vector<std::string>& collect_table_column_names(std::vector<std::string>& collectedExpressions,
@@ -17834,7 +17834,7 @@ namespace sqlite_orm {
1783417834
namespace internal {
1783517835
// collecting column names utilizes the statement serializer
1783617836
template<class T, class C>
17837-
std::string serialize(const T& t, const C& context);
17837+
auto serialize(const T& t, const C& context);
1783817838

1783917839
inline void unquote_identifier(std::string& identifier) {
1784017840
if(!identifier.empty()) {
@@ -18097,6 +18097,8 @@ namespace sqlite_orm {
1809718097

1809818098
// #include "serializing_util.h"
1809918099

18100+
// #include "serialize_result_type.h"
18101+
1810018102
// #include "statement_binder.h"
1810118103

1810218104
// #include "values.h"
@@ -18119,7 +18121,7 @@ namespace sqlite_orm {
1811918121
struct statement_serializer;
1812018122

1812118123
template<class T, class C>
18122-
std::string serialize(const T& t, const C& context) {
18124+
auto serialize(const T& t, const C& context) {
1812318125
statement_serializer<T> serializer;
1812418126
return serializer(t, context);
1812518127
}
@@ -18209,7 +18211,7 @@ namespace sqlite_orm {
1820918211
}
1821018212

1821118213
template<class Ctx>
18212-
std::string serialize(const statement_type& statement, const Ctx& context, const std::string& tableName) {
18214+
auto serialize(const statement_type& statement, const Ctx& context, const std::string& tableName) {
1821318215
std::stringstream ss;
1821418216
ss << "CREATE TABLE " << streaming_identifier(tableName) << " ( "
1821518217
<< streaming_expressions_tuple(statement.elements, context) << ")";
@@ -18487,7 +18489,7 @@ namespace sqlite_orm {
1848718489
using statement_type = rank_t;
1848818490

1848918491
template<class Ctx>
18490-
std::string operator()(const statement_type& /*statement*/, const Ctx&) const {
18492+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx&) const {
1849118493
return "rank";
1849218494
}
1849318495
};
@@ -19011,7 +19013,7 @@ namespace sqlite_orm {
1901119013
using statement_type = conflict_clause_t;
1901219014

1901319015
template<class Ctx>
19014-
std::string operator()(const statement_type& statement, const Ctx&) const {
19016+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
1901519017
switch(statement) {
1901619018
case conflict_clause_t::rollback:
1901719019
return "ROLLBACK";
@@ -19043,7 +19045,7 @@ namespace sqlite_orm {
1904319045
using statement_type = null_t;
1904419046

1904519047
template<class Ctx>
19046-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
19048+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
1904719049
return "NULL";
1904819050
}
1904919051
};
@@ -19053,7 +19055,7 @@ namespace sqlite_orm {
1905319055
using statement_type = not_null_t;
1905419056

1905519057
template<class Ctx>
19056-
std::string operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
19058+
serialize_result_type operator()(const statement_type& /*statement*/, const Ctx& /*context*/) const {
1905719059
return "NOT NULL";
1905819060
}
1905919061
};
@@ -19691,7 +19693,7 @@ namespace sqlite_orm {
1969119693
using statement_type = conflict_action;
1969219694

1969319695
template<class Ctx>
19694-
std::string operator()(const statement_type& statement, const Ctx&) const {
19696+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
1969519697
switch(statement) {
1969619698
case conflict_action::replace:
1969719699
return "REPLACE";
@@ -19714,7 +19716,10 @@ namespace sqlite_orm {
1971419716

1971519717
template<class Ctx>
1971619718
std::string operator()(const statement_type& statement, const Ctx& context) const {
19717-
return "OR " + serialize(statement.action, context);
19719+
std::stringstream ss;
19720+
19721+
ss << "OR " << serialize(statement.action, context);
19722+
return ss.str();
1971819723
}
1971919724
};
1972019725

@@ -19949,7 +19954,7 @@ namespace sqlite_orm {
1994919954
using statement_type = trigger_timing;
1995019955

1995119956
template<class Ctx>
19952-
std::string operator()(const statement_type& statement, const Ctx&) const {
19957+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
1995319958
switch(statement) {
1995419959
case trigger_timing::trigger_before:
1995519960
return "BEFORE";
@@ -19967,7 +19972,7 @@ namespace sqlite_orm {
1996719972
using statement_type = trigger_type;
1996819973

1996919974
template<class Ctx>
19970-
std::string operator()(const statement_type& statement, const Ctx&) const {
19975+
serialize_result_type operator()(const statement_type& statement, const Ctx&) const {
1997119976
switch(statement) {
1997219977
case trigger_type::trigger_delete:
1997319978
return "DELETE";
@@ -20218,7 +20223,7 @@ namespace sqlite_orm {
2021820223
using statement_type = default_values_t;
2021920224

2022020225
template<class Ctx>
20221-
std::string operator()(const statement_type&, const Ctx&) const {
20226+
serialize_result_type operator()(const statement_type&, const Ctx&) const {
2022220227
return "DEFAULT VALUES";
2022320228
}
2022420229
};

0 commit comments

Comments
 (0)