move heck queries into heck.rs
This commit is contained in:
parent
5353b04f29
commit
ced50b363c
2 changed files with 21 additions and 12 deletions
|
@ -1,7 +1,8 @@
|
||||||
use crate::{util::debug_say, DbConnPool};
|
use crate::{util::debug_say, DbConnPool};
|
||||||
use serenity::framework::standard::{macros::command, CommandResult};
|
use serenity::framework::standard::{macros::command, CommandResult};
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::Context;
|
use serenity::{async_trait, prelude::Context};
|
||||||
|
use sqlx::Error;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
async fn heck(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn heck(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
@ -21,3 +22,22 @@ async fn heck(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
|
||||||
Ok(())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,17 +18,6 @@ impl DbConnPool {
|
||||||
pool: init_pool().await?,
|
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 {
|
impl TypeMapKey for DbConnPool {
|
||||||
|
|
Loading…
Reference in a new issue