Skip to content

Commit 86f9458

Browse files
committed
2 parents 7a9202f + 9269b71 commit 86f9458

File tree

124 files changed

+1542
-785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1542
-785
lines changed

frameworks/C++/cutelyst/build.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

3-
export ASQL_VER=0.74.0
3+
export ASQL_VER=0.84.0
44
export CUTELEE_VER=6.1.0
5-
export CUTELYST_VER=3.7.0
5+
export CUTELYST_TAG=v4.0.0-alpha1
6+
export CUTELYST_VER=4.0.0
67

78
apt update -qq && \
89
apt install -yqq --no-install-recommends \
@@ -21,8 +22,8 @@ wget -q https://github.com/cutelyst/cutelee/releases/download/v${CUTELEE_VER}/cu
2122
wget -q https://github.com/cutelyst/asql/releases/download/v${ASQL_VER}/libasql0-qt6_${ASQL_VER}_amd64.deb && \
2223
apt install -yqq ./libasql0-qt6_${ASQL_VER}_amd64.deb
2324

24-
wget -q https://github.com/cutelyst/cutelyst/releases/download/v${CUTELYST_VER}/cutelyst3-qt6_${CUTELYST_VER}_amd64.deb && \
25-
apt install -yqq ./cutelyst3-qt6_${CUTELYST_VER}_amd64.deb
25+
wget -q https://github.com/cutelyst/cutelyst/releases/download/${CUTELYST_TAG}/cutelyst4-qt6_${CUTELYST_VER}_amd64.deb && \
26+
apt install -yqq ./cutelyst4-qt6_${CUTELYST_VER}_amd64.deb
2627

2728
cd ${TROOT} && \
2829
mkdir -p build && \

frameworks/C++/cutelyst/src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ FetchContent_Declare(
1414
FetchContent_MakeAvailable(mimalloc)
1515

1616
find_package(Qt6 6.2.0 REQUIRED COMPONENTS Core Network Sql)
17-
find_package(ASqlQt6 0.74 REQUIRED)
18-
find_package(Cutelyst3Qt6 3.6 REQUIRED)
17+
find_package(ASqlQt6 0.84 REQUIRED)
18+
find_package(Cutelyst4Qt6 3.6 REQUIRED)
1919
find_package(Cutelee6Qt6 6.1.0 REQUIRED)
2020
find_package(PostgreSQL REQUIRED)
2121

frameworks/C++/cutelyst/src/cachedqueries.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CachedQueries::CachedQueries(QObject *parent)
2020

2121
void CachedQueries::cached_queries(Context *c)
2222
{
23-
int queries = c->request()->queryParam(QStringLiteral("count")).toInt();
23+
int queries = c->request()->queryParam(u"count"_qs).toInt();
2424
if (queries < 1) {
2525
queries = 1;
2626
} else if (queries > 500) {
@@ -48,8 +48,8 @@ void CachedQueries::cached_queries(Context *c)
4848
auto it = result.begin();
4949
int id = it[0].toInt();
5050
auto obj = new QJsonObject({
51-
{QStringLiteral("id"), id},
52-
{QStringLiteral("randomNumber"), it[1].toInt()}
51+
{u"id"_qs, id},
52+
{u"randomNumber"_qs, it[1].toInt()}
5353
});
5454
array->append(*obj);
5555
cache.insert(id, obj, 1);

frameworks/C++/cutelyst/src/cutelyst-benchmarks.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cutelyst_benchmarks::~cutelyst_benchmarks()
4040

4141
bool cutelyst_benchmarks::init()
4242
{
43-
if (config(QStringLiteral("SendDate")).value<bool>()) {
43+
if (config(u"SendDate"_qs).value<bool>()) {
4444
qDebug() << "Manually send date";
4545
auto dateT = new QTimer(this);
4646
dateT->setInterval(1000);
@@ -63,9 +63,9 @@ bool cutelyst_benchmarks::init()
6363
new CachedQueries(this);
6464

6565
if (defaultHeaders().server().isEmpty()) {
66-
defaultHeaders().setServer(QStringLiteral("Cutelyst"));
66+
defaultHeaders().setServer("Cutelyst"_qba);
6767
}
68-
defaultHeaders().removeHeader(QStringLiteral("X-Cutelyst"));
68+
defaultHeaders().removeHeader("X-Cutelyst");
6969

7070
return true;
7171
}
@@ -75,48 +75,43 @@ bool cutelyst_benchmarks::postFork()
7575
QMutexLocker locker(&mutex); // QSqlDatabase::addDatabase is not thread-safe
7676

7777
QSqlDatabase db;
78-
const auto driver = config(QStringLiteral("Driver")).toString();
78+
const auto driver = config(u"Driver"_qs).toString();
7979
if (driver == u"QPSQL") {
80-
db = QSqlDatabase::addDatabase(driver, Sql::databaseNameThread(QStringLiteral("postgres")));
81-
db.setDatabaseName(QStringLiteral("hello_world"));
82-
db.setUserName(QStringLiteral("benchmarkdbuser"));
83-
db.setPassword(QStringLiteral("benchmarkdbpass"));
84-
db.setHostName(config(QStringLiteral("DatabaseHostName")).toString());
80+
db = QSqlDatabase::addDatabase(driver, Sql::databaseNameThread(u"postgres"_qs));
81+
db.setDatabaseName(u"hello_world"_qs);
82+
db.setUserName(u"benchmarkdbuser"_qs);
83+
db.setPassword(u"benchmarkdbpass"_qs);
84+
db.setHostName(config(u"DatabaseHostName"_qs).toString());
8585
if (!db.open()) {
8686
qDebug() << "Error opening PostgreSQL db:" << db << db.connectionName() << db.lastError().databaseText();
8787
return false;
8888
}
8989
} else if (driver == u"QMYSQL") {
90-
db = QSqlDatabase::addDatabase(driver, Sql::databaseNameThread(QStringLiteral("mysql")));
91-
db.setDatabaseName(QStringLiteral("hello_world"));
92-
db.setUserName(QStringLiteral("benchmarkdbuser"));
93-
db.setPassword(QStringLiteral("benchmarkdbpass"));
94-
db.setHostName(config(QStringLiteral("DatabaseHostName")).toString());
90+
db = QSqlDatabase::addDatabase(driver, Sql::databaseNameThread(u"mysql"_qs));
91+
db.setDatabaseName(u"hello_world"_qs);
92+
db.setUserName(u"benchmarkdbuser"_qs);
93+
db.setPassword(u"benchmarkdbpass"_qs);
94+
db.setHostName(config(u"DatabaseHostName"_qs).toString());
9595
if (!db.open()) {
9696
qDebug() << "Error opening MySQL db:" << db << db.connectionName() << db.lastError().databaseText();
9797
return false;
9898
}
9999
} else if (driver == u"postgres") {
100-
QUrl uri(QStringLiteral("postgresql://benchmarkdbuser:benchmarkdbpass@server/hello_world"));
101-
uri.setHost(config(QStringLiteral("DatabaseHostName")).toString());
100+
QUrl uri(u"postgresql://benchmarkdbuser:benchmarkdbpass@server/hello_world"_qs);
101+
uri.setHost(config(u"DatabaseHostName"_qs).toString());
102102
qDebug() << "ASql URI:" << uri.toString();
103103

104104
APool::create(ASql::APg::factory(uri.toString()));
105105
APool::setMaxIdleConnections(128);
106-
APool::setSetupCallback([](ADatabase &db) {
106+
APool::setSetupCallback([](ADatabase db) {
107107
// Enable Pipeline mode
108108
db.enterPipelineMode(500);
109109
});
110110
}
111111

112112
qDebug() << "Connections" << QCoreApplication::applicationPid() << QThread::currentThread() << QSqlDatabase::connectionNames();
113-
// db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), QLatin1String("sqlite"));
114-
// if (!db.open()) {
115-
// qDebug() << "Error opening db:" << db << db.lastError().databaseText();
116-
// return false;
117-
// }
118113

119114
return true;
120115
}
121116

122-
//#include "moc_cutelyst-benchmarks.cpp"
117+
#include "moc_cutelyst-benchmarks.cpp"

frameworks/C++/cutelyst/src/databaseupdatestest.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ DatabaseUpdatesTest::DatabaseUpdatesTest(QObject *parent) : Controller(parent)
2525

2626
void DatabaseUpdatesTest::updatep(Context *c)
2727
{
28-
int queries = c->request()->queryParam(QStringLiteral("queries"), QStringLiteral("1")).toInt();
28+
int queries = c->request()->queryParam(u"queries"_qs, u"1"_qs).toInt();
2929
if (queries < 1) {
3030
queries = 1;
3131
} else if (queries > 500) {
@@ -66,7 +66,7 @@ void DatabaseUpdatesTest::updatep(Context *c)
6666

6767
void DatabaseUpdatesTest::updateb(Context *c)
6868
{
69-
int queries = c->request()->queryParam(QStringLiteral("queries"), QStringLiteral("1")).toInt();
69+
int queries = c->request()->queryParam(u"queries"_qs, u"1"_qs).toInt();
7070
if (queries < 1) {
7171
queries = 1;
7272
} else if (queries > 500) {
@@ -117,30 +117,30 @@ void DatabaseUpdatesTest::updateb(Context *c)
117117
void DatabaseUpdatesTest::updates_postgres(Context *c)
118118
{
119119
QSqlQuery query = CPreparedSqlQueryThreadForDB(
120-
QLatin1String("SELECT id, randomNumber FROM world WHERE id = :id"),
121-
QStringLiteral("postgres"));
120+
u"SELECT id, randomNumber FROM world WHERE id = :id"_qs,
121+
u"postgres"_qs);
122122
QSqlQuery updateQuery = CPreparedSqlQueryThreadForDB(
123-
QLatin1String("UPDATE world SET randomNumber = :randomNumber WHERE id = :id"),
124-
QStringLiteral("postgres"));
123+
u"UPDATE world SET randomNumber = :randomNumber WHERE id = :id"_qs,
124+
u"postgres"_qs);
125125
processQuery(c, query, updateQuery);
126126
}
127127

128128
void DatabaseUpdatesTest::updates_mysql(Context *c)
129129
{
130130
QSqlQuery query = CPreparedSqlQueryThreadForDB(
131-
QLatin1String("SELECT randomNumber, id FROM world WHERE id = :id"),
132-
QStringLiteral("mysql"));
131+
u"SELECT randomNumber, id FROM world WHERE id = :id"_qs,
132+
u"mysql"_qs);
133133
QSqlQuery updateQuery = CPreparedSqlQueryThreadForDB(
134-
QLatin1String("UPDATE world SET randomNumber = :randomNumber WHERE id = :id"),
135-
QStringLiteral("mysql"));
134+
u"UPDATE world SET randomNumber = :randomNumber WHERE id = :id"_qs,
135+
u"mysql"_qs);
136136
processQuery(c, query, updateQuery);
137137
}
138138

139139
void DatabaseUpdatesTest::processQuery(Context *c, QSqlQuery &query, QSqlQuery &updateQuery)
140140
{
141141
QJsonArray array;
142142

143-
int queries = c->request()->queryParam(QStringLiteral("queries"), QStringLiteral("1")).toInt();
143+
int queries = c->request()->queryParam(u"queries"_qs, u"1"_qs).toInt();
144144
if (queries < 1) {
145145
queries = 1;
146146
} else if (queries > 500) {
@@ -153,7 +153,7 @@ void DatabaseUpdatesTest::processQuery(Context *c, QSqlQuery &query, QSqlQuery &
153153
for (int i = 0; i < queries; ++i) {
154154
int id = (rand() % 10000) + 1;
155155

156-
query.bindValue(QStringLiteral(":id"), id);
156+
query.bindValue(u":id"_qs, id);
157157
if (Q_UNLIKELY(!query.exec() || !query.next())) {
158158
c->res()->setStatus(Response::InternalServerError);
159159
return;
@@ -164,13 +164,13 @@ void DatabaseUpdatesTest::processQuery(Context *c, QSqlQuery &query, QSqlQuery &
164164
randomNumbers.append(randomNumber);
165165

166166
array.append(QJsonObject{
167-
{QStringLiteral("id"), id},
168-
{QStringLiteral("randomNumber"), randomNumber}
167+
{u"id"_qs, id},
168+
{u"randomNumber"_qs, randomNumber}
169169
});
170170
}
171171

172-
updateQuery.bindValue(QStringLiteral(":id"), ids);
173-
updateQuery.bindValue(QStringLiteral(":randomNumber"), randomNumbers);
172+
updateQuery.bindValue(u":id"_qs, ids);
173+
updateQuery.bindValue(u":randomNumber"_qs, randomNumbers);
174174
if (Q_LIKELY(updateQuery.execBatch())) {
175175
c->response()->setJsonArrayBody(array);
176176
} else {
@@ -182,24 +182,24 @@ APreparedQuery DatabaseUpdatesTest::getSql(int count)
182182
{
183183
auto iter = m_sqlMap.find(count);
184184
if (Q_UNLIKELY(iter == m_sqlMap.end())) {
185-
QString sql = QStringLiteral("UPDATE WORLD SET randomnumber=CASE id ");
185+
QString sql = u"UPDATE WORLD SET randomnumber=CASE id "_qs;
186186
sql.reserve(80 + count * 25);
187187
int placeholdersCounter = 1;
188188
for (int i = 0; i < count; i++) {
189-
sql.append(QStringLiteral("WHEN $%1 THEN $%2 ").arg(placeholdersCounter).arg(placeholdersCounter + 1));
189+
sql.append(u"WHEN $%1 THEN $%2 "_qs.arg(placeholdersCounter).arg(placeholdersCounter + 1));
190190
placeholdersCounter += 2;
191191
}
192-
sql.append(QStringLiteral("ELSE randomnumber END WHERE id IN ("));
192+
sql.append(u"ELSE randomnumber END WHERE id IN (");
193193

194194
for (int i = 0; i < count; i++) {
195-
sql.append(QLatin1Char('$') + QString::number(placeholdersCounter) + QLatin1Char(','));
195+
sql.append(u'$' + QString::number(placeholdersCounter) + u',');
196196
++placeholdersCounter;
197197
}
198198

199199
if (count) {
200200
sql.remove(sql.size() - 1, 1);
201201
}
202-
sql.append(QLatin1Char(')'));
202+
sql.append(u')');
203203

204204
iter = m_sqlMap.insert(count, APreparedQuery(sql));
205205
}

frameworks/C++/cutelyst/src/fortunetest.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void FortuneTest::fortunes_raw_p(Context *c)
3333
fortunes.emplace_back(Fortune{it[0].toInt(), it[1].toString()});
3434
++it;
3535
}
36-
fortunes.emplace_back(Fortune{0, QStringLiteral("Additional fortune added at request time.")});
36+
fortunes.emplace_back(Fortune{0, u"Additional fortune added at request time."_qs});
3737

3838
std::sort(fortunes.begin(), fortunes.end(), [] (const Fortune &a1, const Fortune &a2) {
3939
return a1.message < a2.message;
@@ -46,17 +46,17 @@ void FortuneTest::fortunes_raw_p(Context *c)
4646
void FortuneTest::fortunes_raw_postgres(Context *c)
4747
{
4848
QSqlQuery query = CPreparedSqlQueryThreadForDB(
49-
QLatin1String("SELECT id, message FROM fortune"),
50-
QStringLiteral("postgres"));
49+
u"SELECT id, message FROM fortune"_qs,
50+
u"postgres"_qs);
5151
auto fortunes = processQuery(c, query);
5252
renderRaw(c, fortunes);
5353
}
5454

5555
void FortuneTest::fortunes_raw_mysql(Context *c)
5656
{
5757
QSqlQuery query = CPreparedSqlQueryThreadForDB(
58-
QLatin1String("SELECT id, message FROM fortune"),
59-
QStringLiteral("mysql"));
58+
u"SELECT id, message FROM fortune"_qs,
59+
u"mysql"_qs);
6060
auto fortunes = processQuery(c, query);
6161
renderRaw(c, fortunes);
6262
}
@@ -82,59 +82,59 @@ void FortuneTest::fortunes_c_p(Context *c)
8282
}
8383

8484
fortunes.append(QVariant::fromValue(QVariantList{
85-
{0, QStringLiteral("Additional fortune added at request time.")},
85+
{0, u"Additional fortune added at request time."_qs},
8686
}));
8787
std::sort(fortunes.begin(), fortunes.end(), [] (const QVariant &a1, const QVariant &a2) {
8888
return a1.toList()[1].toString() < a2.toList()[1].toString();
8989
});
9090

91-
c->setStash(QStringLiteral("template"), QStringLiteral("fortunes.html"));
92-
c->setStash(QStringLiteral("fortunes"), fortunes);
91+
c->setStash(u"template"_qs, u"fortunes.html"_qs);
92+
c->setStash(u"fortunes"_qs, fortunes);
9393
static thread_local View *view = c->view();
9494
view->execute(c);
95-
c->response()->setContentType(QStringLiteral("text/html; charset=UTF-8"));
95+
c->response()->setContentType("text/html; charset=UTF-8"_qba);
9696
});
9797
}
9898

9999
void FortuneTest::fortunes_cutelee_postgres(Context *c)
100100
{
101101
QSqlQuery query = CPreparedSqlQueryThreadForDB(
102-
QLatin1String("SELECT id, message FROM fortune"),
103-
QStringLiteral("postgres"));
102+
u"SELECT id, message FROM fortune"_qs,
103+
u"postgres"_qs);
104104
if (query.exec()) {
105105
QVariantList fortunes = Sql::queryToList(query);
106106
fortunes.append(QVariant::fromValue(QVariantList{
107-
{0, QStringLiteral("Additional fortune added at request time.")},
107+
{0, u"Additional fortune added at request time."_qs},
108108
}));
109109
std::sort(fortunes.begin(), fortunes.end(), [] (const QVariant &a1, const QVariant &a2) {
110110
return a1.toList()[1].toString() < a2.toList()[1].toString();
111111
});
112-
c->setStash(QStringLiteral("template"), QStringLiteral("fortunes.html"));
113-
c->setStash(QStringLiteral("fortunes"), fortunes);
112+
c->setStash(u"template"_qs, u"fortunes.html"_qs);
113+
c->setStash(u"fortunes"_qs, fortunes);
114114
static thread_local View *view = c->view();
115115
view->execute(c);
116-
c->response()->setContentType(QStringLiteral("text/html; charset=UTF-8"));
116+
c->response()->setContentType("text/html; charset=UTF-8"_qba);
117117
}
118118
}
119119

120120
void FortuneTest::fortunes_cutelee_mysql(Context *c)
121121
{
122122
QSqlQuery query = CPreparedSqlQueryThreadForDB(
123-
QLatin1String("SELECT id, message FROM fortune"),
124-
QStringLiteral("mysql"));
123+
u"SELECT id, message FROM fortune"_qs,
124+
u"mysql"_qs);
125125
if (query.exec()) {
126126
QVariantList fortunes = Sql::queryToList(query);
127127
fortunes.append(QVariant::fromValue(QVariantList{
128-
{0, QStringLiteral("Additional fortune added at request time.")},
128+
{0, u"Additional fortune added at request time."_qs},
129129
}));
130130
std::sort(fortunes.begin(), fortunes.end(), [] (const QVariant &a1, const QVariant &a2) {
131131
return a1.toList()[1].toString() < a2.toList()[1].toString();
132132
});
133-
c->setStash(QStringLiteral("template"), QStringLiteral("fortunes.html"));
134-
c->setStash(QStringLiteral("fortunes"), fortunes);
133+
c->setStash(u"template"_qs, u"fortunes.html"_qs);
134+
c->setStash(u"fortunes"_qs, fortunes);
135135
static thread_local View *view = c->view();
136136
view->execute(c);
137-
c->response()->setContentType(QStringLiteral("text/html; charset=UTF-8"));
137+
c->response()->setContentType("text/html; charset=UTF-8"_qba);
138138
}
139139
}
140140

@@ -151,7 +151,7 @@ FortuneList FortuneTest::processQuery(Context *c, QSqlQuery &query)
151151
while (query.next()) {
152152
fortunes.push_back({query.value(0).toInt(), query.value(1).toString()});
153153
}
154-
fortunes.push_back({0, QStringLiteral("Additional fortune added at request time.")});
154+
fortunes.push_back({0, u"Additional fortune added at request time."_qs});
155155

156156
std::sort(fortunes.begin(), fortunes.end(), [] (const Fortune &a1, const Fortune &a2) {
157157
return a1.message < a2.message;
@@ -183,5 +183,5 @@ void FortuneTest::renderRaw(Context *c, const FortuneList &fortunes) const
183183

184184
auto response = c->response();
185185
response->setBody(out);
186-
response->setContentType(QStringLiteral("text/html; charset=UTF-8"));
186+
response->setContentType("text/html; charset=UTF-8"_qba);
187187
}

frameworks/C++/cutelyst/src/jsontest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ JsonTest::JsonTest(QObject *parent) : Controller(parent)
1212

1313
void JsonTest::json(Context *c)
1414
{
15-
c->response()->setJsonObjectBody({ {QStringLiteral("message"), QStringLiteral("Hello, World!")} });
15+
c->response()->setJsonObjectBody({ {u"message"_qs, u"Hello, World!"_qs} });
1616
}
1717

1818
void JsonTest::pson(Context *c)

0 commit comments

Comments
 (0)