Implement drop table for the table builder, fix a warning, and made the message page's migration runnable multiple times (for now).

This commit is contained in:
Relintai 2020-12-02 00:49:17 +01:00
parent b99cbf0164
commit 53a2a651d6
6 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,7 @@ void Database::connect(const std::string &connection_str) {
} }
QueryResult *Database::query(const std::string &query) { QueryResult *Database::query(const std::string &query) {
return nullptr;
} }
void Database::query_run(const std::string &query) { void Database::query_run(const std::string &query) {
} }

View File

@ -40,6 +40,10 @@ TableBuilder *TableBuilder::next_row() {
return this; return this;
} }
TableBuilder *TableBuilder::drop_table(const std::string &name) {
}
void TableBuilder::finalize() { void TableBuilder::finalize() {
} }

View File

@ -16,6 +16,8 @@ public:
virtual TableBuilder *primary_key(); virtual TableBuilder *primary_key();
virtual TableBuilder *next_row(); virtual TableBuilder *next_row();
virtual TableBuilder *drop_table(const std::string &name);
virtual void finalize(); virtual void finalize();
TableBuilder(); TableBuilder();

View File

@ -64,6 +64,11 @@ void MysqlTableBuilder::finalize() {
result += ");"; result += ");";
} }
TableBuilder *MysqlTableBuilder::drop_table(const std::string &name) {
result += "DROP TABLE " + name + ";";
return this;
}
MysqlTableBuilder::MysqlTableBuilder() { MysqlTableBuilder::MysqlTableBuilder() {
} }

View File

@ -18,6 +18,8 @@ public:
TableBuilder *primary_key(); TableBuilder *primary_key();
TableBuilder *next_row(); TableBuilder *next_row();
TableBuilder *drop_table(const std::string &name);
void finalize(); void finalize();
MysqlTableBuilder(); MysqlTableBuilder();

View File

@ -43,6 +43,13 @@ void MessagePage::index(Request *request) {
void MessagePage::migrate() { void MessagePage::migrate() {
TableBuilder *t = db->get_table_builder(); TableBuilder *t = db->get_table_builder();
t->drop_table("message_page");
db->query_run(t->result);
printf("%s\n", t->result.c_str());
t->result.clear();
t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->finalize(); t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->finalize();
printf("%s\n", t->result.c_str()); printf("%s\n", t->result.c_str());