diff options
author | Cara Salter <cara@devcara.com> | 2023-04-23 15:04:34 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-04-23 15:04:34 -0400 |
commit | b629b237da6c7618ae7e679a2c9b879c6019662d (patch) | |
tree | 2aded5e0b797e26f7774052dfedc0951d2adc4a4 /src | |
parent | 6c16d4315b5d97316db25b5a79ccee8fa1d4e953 (diff) | |
download | 142bot-b629b237da6c7618ae7e679a2c9b879c6019662d.tar.gz 142bot-b629b237da6c7618ae7e679a2c9b879c6019662d.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bot.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
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; } |