move heck queries into heck.rs

This commit is contained in:
Edward Shen 2020-05-02 23:58:15 -04:00
parent 5353b04f29
commit ced50b363c
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 21 additions and 12 deletions

View file

@ -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<i32, Error>;
}
#[async_trait]
impl HeckQueries for DbConnPool {
async fn get_heck(&self) -> Result<i32, Error> {
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)
}
}

View file

@ -18,17 +18,6 @@ impl DbConnPool {
pool: init_pool().await?,
})
}
pub async fn get_heck(&self) -> Result<i32, Error> {
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 {