introduce db pool type instead of hard-coded SqlitePool

This commit is contained in:
mykola2312 2024-03-02 03:07:12 +02:00
parent 1e6d671feb
commit 7fac64f8e4
2 changed files with 7 additions and 4 deletions

View file

@ -5,14 +5,13 @@ use std::fmt;
use std::str; use std::str;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use teloxide::dispatching::dialogue; use teloxide::dispatching::{dialogue, dialogue::InMemStorage, UpdateHandler};
use teloxide::dispatching::dialogue::InMemStorage;
use teloxide::dispatching::UpdateHandler;
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands}; use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
use tracing::{event, Level}; use tracing::{event, Level};
use super::dl::cmd_download; use super::dl::cmd_download;
use super::types::*; use super::types::*;
use crate::db::DbPool;
fn parse_env<T>(name: &str) -> T fn parse_env<T>(name: &str) -> T
where where
@ -74,7 +73,7 @@ enum Command {
Download(String), Download(String),
} }
async fn cmd_test(bot: Bot, msg: Message, _db: SqlitePool) -> HandlerResult { async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
bot.send_message(msg.chat.id, "test response").await?; bot.send_message(msg.chat.id, "test response").await?;
Ok(()) Ok(())

View file

@ -3,6 +3,8 @@ use sqlx::{Sqlite, SqlitePool};
use super::util::make_database_url; use super::util::make_database_url;
pub type DbPool = SqlitePool;
#[derive(sqlx::FromRow)] #[derive(sqlx::FromRow)]
pub struct User { pub struct User {
pub id: i64, pub id: i64,
@ -14,6 +16,8 @@ pub struct User {
pub is_admin: i64, pub is_admin: i64,
} }
pub mod user;
#[derive(sqlx::FromRow)] #[derive(sqlx::FromRow)]
pub struct Chat { pub struct Chat {
pub id: i64, pub id: i64,