introduce db pool type instead of hard-coded SqlitePool

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

View file

@ -5,14 +5,13 @@ use std::fmt;
use std::str;
use std::str::FromStr;
use std::time::Duration;
use teloxide::dispatching::dialogue;
use teloxide::dispatching::dialogue::InMemStorage;
use teloxide::dispatching::UpdateHandler;
use teloxide::dispatching::{dialogue, dialogue::InMemStorage, UpdateHandler};
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
use tracing::{event, Level};
use super::dl::cmd_download;
use super::types::*;
use crate::db::DbPool;
fn parse_env<T>(name: &str) -> T
where
@ -74,7 +73,7 @@ enum Command {
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?;
Ok(())

View file

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