|
@@ -1,6 +1,7 @@
|
|
|
#include "fortunetest.h"
|
|
|
|
|
|
#include <Cutelyst/Plugins/Utils/Sql>
|
|
|
+#include <Cutelyst/View>
|
|
|
|
|
|
#include <QSqlQuery>
|
|
|
|
|
@@ -27,6 +28,50 @@ void FortuneTest::fortunes_raw_mysql(Context *c)
|
|
|
renderRaw(c, fortunes);
|
|
|
}
|
|
|
|
|
|
+void FortuneTest::fortunes_grantlee_postgres(Context *c)
|
|
|
+{
|
|
|
+ QSqlQuery query = CPreparedSqlQueryThreadForDB(
|
|
|
+ QLatin1String("SELECT id, message FROM fortune"),
|
|
|
+ QStringLiteral("postgres"));
|
|
|
+ if (query.exec()) {
|
|
|
+ QVariantList fortunes = Sql::queryToMapList(query);
|
|
|
+ fortunes.append(QVariantMap{
|
|
|
+ {QStringLiteral("id"), 0},
|
|
|
+ {QStringLiteral("message"), QStringLiteral("Additional fortune added at request time.")},
|
|
|
+ });
|
|
|
+ std::sort(fortunes.begin(), fortunes.end(), [] (const QVariant &a1, const QVariant &a2) {
|
|
|
+ return a1.toMap()[QStringLiteral("message")].toString() < a2.toMap()[QStringLiteral("message")].toString();
|
|
|
+ });
|
|
|
+ c->setStash(QStringLiteral("template"), QStringLiteral("fortunes.html"));
|
|
|
+ c->setStash(QStringLiteral("fortunes"), fortunes);
|
|
|
+ static thread_local View *view = c->view();
|
|
|
+ view->execute(c);
|
|
|
+ c->response()->setContentType(QStringLiteral("text/html; charset=UTF-8"));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void FortuneTest::fortunes_grantlee_mysql(Context *c)
|
|
|
+{
|
|
|
+ QSqlQuery query = CPreparedSqlQueryThreadForDB(
|
|
|
+ QLatin1String("SELECT id, message FROM fortune"),
|
|
|
+ QStringLiteral("mysql"));
|
|
|
+ if (query.exec()) {
|
|
|
+ QVariantList fortunes = Sql::queryToMapList(query);
|
|
|
+ fortunes.append(QVariantMap{
|
|
|
+ {QStringLiteral("id"), 0},
|
|
|
+ {QStringLiteral("message"), QStringLiteral("Additional fortune added at request time.")},
|
|
|
+ });
|
|
|
+ std::sort(fortunes.begin(), fortunes.end(), [] (const QVariant &a1, const QVariant &a2) {
|
|
|
+ return a1.toMap()[QStringLiteral("message")].toString() < a2.toMap()[QStringLiteral("message")].toString();
|
|
|
+ });
|
|
|
+ c->setStash(QStringLiteral("template"), QStringLiteral("fortunes.html"));
|
|
|
+ c->setStash(QStringLiteral("fortunes"), fortunes);
|
|
|
+ static thread_local View *view = c->view();
|
|
|
+ view->execute(c);
|
|
|
+ c->response()->setContentType(QStringLiteral("text/html; charset=UTF-8"));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
FortuneList FortuneTest::processQuery(Context *c, QSqlQuery &query)
|
|
|
{
|
|
|
FortuneList fortunes;
|