From b629b237da6c7618ae7e679a2c9b879c6019662d Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 23 Apr 2023 15:04:34 -0400 Subject: sql: Implement bot state Allows for persistent, dynamic storage of configuration options outside of the config.json file. The bot_state table is, essentially, a key-value store for config options. There are two new prepared statements, `state` and `update_state`: - `state` will return the value for the provided key - `update_state` will create the key or update an existing key --- src/bot.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/bot.cpp b/src/bot.cpp index 2bc6a6b..b1d530c 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -67,9 +67,20 @@ bool Bot::run_database_migrations() { w.commit(); this->core->log(dpp::ll_info, "Done."); + this->core->log(dpp::ll_info, "Preparing statements..."); + create_queries(); + this->core->log(dpp::ll_info, "Done"); + return true; } +void Bot::create_queries() { + this->core->log(dpp::ll_trace, "Preparing state query"); + this->conn.prepare("state", "SELECT value FROM bot_state WHERE setting=$1"); + this->core->log(dpp::ll_trace, "Preparing update state query"); + this->conn.prepare("update_state", "INSERT INTO bot_state (setting,value) VALUES ($1, $2) ON CONFLICT (setting) DO UPDATE SET value=EXCLUDED.value;"); +} + bool Bot::isDevMode() { return dev; } -- cgit v1.2.3