rcpp_framework/modules/message_page/message_page.cpp

51 lines
985 B
C++
Raw Normal View History

2020-12-01 17:01:59 +01:00
#include "message_page.h"
#include "core/database.h"
2020-12-01 22:23:28 +01:00
#include "core/query_builder.h"
2020-12-01 17:01:59 +01:00
void MessagePage::index(Request *request) {
QueryBuilder *b = db->get_query_builder();
2020-12-01 22:23:28 +01:00
b->select("*")->from("tutorials_tbl")->finalize();
2020-12-01 22:23:28 +01:00
db->query(b->query_result);
2020-12-01 22:23:28 +01:00
delete b;
2020-12-01 22:24:23 +01:00
2020-12-01 22:23:28 +01:00
/*
db->query("show databases;");
db->query("show tables;");
db->query("SELECT * FROM tutorials_tbl;");
2020-12-01 22:23:28 +01:00
*/
2020-12-01 17:01:59 +01:00
std::string r = "<html><body>";
2020-12-01 17:01:59 +01:00
for (uint32_t i = 0; i < messages.size(); ++i) {
r += "<p>" + messages[i] + "</p><br>";
}
2020-12-01 17:01:59 +01:00
r += "</html></body>";
2020-12-01 17:01:59 +01:00
request->response->setBody(r);
request->send();
}
void MessagePage::migrate() {
TableBuilder *t = db->get_table_builder();
t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("dd", 30)->finalize();
db->query(t->result);
delete t;
2020-12-01 17:01:59 +01:00
}
MessagePage::MessagePage() :
Object() {
messages.push_back("T message 1");
messages.push_back("T message 2");
}
2020-12-01 17:01:59 +01:00
MessagePage::~MessagePage() {
2020-12-01 17:01:59 +01:00
}