revert idea with Arc<DbPool> because sqlx is already Arc internally

This commit is contained in:
mykola2312 2024-03-02 17:57:32 +02:00
parent 24bdf0593e
commit 89a12defee
4 changed files with 7 additions and 7 deletions

View file

@ -8,7 +8,7 @@ use crate::db::DbPool;
pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
let admins: i64 = sqlx::query("SELECT COUNT(*) FROM user WHERE is_admin = 1")
.fetch_one(db.as_ref())
.fetch_one(&db)
.await?
.get(0);
@ -30,7 +30,7 @@ pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
let target = find_or_create_user(&db, target).await?;
sqlx::query("UPDATE user SET can_download = 1, is_admin = 1 WHERE id = $1;")
.bind(target.id)
.execute(db.as_ref())
.execute(&db)
.await?;
event!(

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use super::util::make_database_url;
pub type DbPool = Arc<SqlitePool>;
pub type DbPool = SqlitePool;
#[derive(sqlx::FromRow)]
pub struct User {

View file

@ -19,12 +19,12 @@ pub async fn create_user(
.bind(&user.last_name)
.bind(can_download as i64)
.bind(is_admin as i64)
.execute(db.as_ref())
.execute(db)
.await?;
let user: User = sqlx::query_as("SELECT * FROM user WHERE tg_id = $1 LIMIT 1;")
.bind(user.id.0 as i64)
.fetch_one(db.as_ref())
.fetch_one(db)
.await?;
Ok(user)
}
@ -33,7 +33,7 @@ pub async fn find_or_create_user(db: &DbPool, user: &types::User) -> Result<User
let res: Result<User, sqlx::Error> =
sqlx::query_as("SELECT * FROM user WHERE tg_id = $1 LIMIT 1;")
.bind(user.id.0 as i64)
.fetch_one(db.as_ref())
.fetch_one(db)
.await;
match res {

View file

@ -22,6 +22,6 @@ async fn main() -> anyhow::Result<()> {
log_init();
let db = db_init().await;
bot_main(Arc::from(db)).await?;
bot_main(db).await?;
Ok(())
}