From aa499ead1c4b21a8311bfd6e2328282d28b0eea5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 25 Feb 2026 21:54:08 +0100 Subject: [PATCH] feat(database): adding the anyhow result return for bot function --- src/database/bot.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/database/bot.rs b/src/database/bot.rs index 5819933..c895ec3 100644 --- a/src/database/bot.rs +++ b/src/database/bot.rs @@ -1,16 +1,17 @@ use sqlx::{PgPool, query, query_as}; use crate::models::bot::{DbBot, BotPresence, BotActivity}; +use anyhow::Result; const BOT_ID: i32 = 1; -pub async fn init(db: &PgPool) -> Result<(), sqlx::Error> { +pub async fn init(db: &PgPool) -> Result<()> { query!("INSERT INTO bots (id) VALUES ($1) ON CONFLICT DO NOTHING", BOT_ID) .execute(db) .await?; Ok(()) } -pub async fn get(db: &PgPool) -> Result, sqlx::Error> { +pub async fn get(db: &PgPool) -> Result> { let bot: Option = query_as!( DbBot, r#"SELECT status, activity_type as "activity_type: BotActivity", presence as "presence: BotPresence" FROM bots WHERE id = $1"#, @@ -21,21 +22,21 @@ pub async fn get(db: &PgPool) -> Result, sqlx::Error> { Ok(bot) } -pub async fn set_status(db: &PgPool, status: &str) -> Result<(), sqlx::Error> { +pub async fn set_status(db: &PgPool, status: &str) -> Result<()> { query!("UPDATE bots SET status = $1 WHERE id = $2", status, BOT_ID) .execute(db) .await?; Ok(()) } -pub async fn set_activity(db: &PgPool, activity: BotActivity) -> Result<(), sqlx::Error> { +pub async fn set_activity(db: &PgPool, activity: BotActivity) -> Result<()> { query!("UPDATE bots SET activity_type = $1::bot_activity WHERE id = $2", activity as BotActivity, BOT_ID) .execute(db) .await?; Ok(()) } -pub async fn set_presence(db: &PgPool, presence: BotPresence) -> Result<(), sqlx::Error> { +pub async fn set_presence(db: &PgPool, presence: BotPresence) -> Result<()> { query!("UPDATE bots SET presence = $1::bot_presence WHERE id = $2", presence as BotPresence, BOT_ID) .execute(db) .await?;