diff --git a/src/commands/heck.rs b/src/commands/heck.rs index 7355eea..2dc17f7 100644 --- a/src/commands/heck.rs +++ b/src/commands/heck.rs @@ -1,7 +1,8 @@ use crate::{util::debug_say, DbConnPool}; use serenity::framework::standard::{macros::command, CommandResult}; use serenity::model::channel::Message; -use serenity::prelude::Context; +use serenity::{async_trait, prelude::Context}; +use sqlx::Error; #[command] async fn heck(ctx: &Context, msg: &Message) -> CommandResult { @@ -21,3 +22,22 @@ async fn heck(ctx: &Context, msg: &Message) -> CommandResult { Ok(()) } + +#[async_trait] +trait HeckQueries { + async fn get_heck(&self) -> Result; +} + +#[async_trait] +impl HeckQueries for DbConnPool { + async fn get_heck(&self) -> Result { + sqlx::query!("UPDATE Heck SET count = count + 1") + .execute(&self.pool) + .await?; + + Ok(sqlx::query!("SELECT count FROM Heck") + .fetch_one(&self.pool) + .await? + .count) + } +} diff --git a/src/util/db.rs b/src/util/db.rs index f63eb9e..305ef08 100644 --- a/src/util/db.rs +++ b/src/util/db.rs @@ -18,17 +18,6 @@ impl DbConnPool { pool: init_pool().await?, }) } - - pub async fn get_heck(&self) -> Result { - sqlx::query!("UPDATE Heck SET count = count + 1") - .execute(&self.pool) - .await?; - - Ok(sqlx::query!("SELECT count FROM Heck") - .fetch_one(&self.pool) - .await? - .count) - } } impl TypeMapKey for DbConnPool {