27 lines
507 B
Rust
27 lines
507 B
Rust
use serenity::prelude::TypeMapKey;
|
|
use sqlx::{
|
|
sqlite::{SqliteConnection, SqlitePool},
|
|
Error, Pool,
|
|
};
|
|
use std::env;
|
|
|
|
type DbPool = Pool<SqliteConnection>;
|
|
|
|
pub(crate) struct DbConnPool {
|
|
pub pool: DbPool,
|
|
}
|
|
|
|
impl DbConnPool {
|
|
pub async fn new() -> Result<Self, Error> {
|
|
Ok(Self {
|
|
pool: SqlitePool::builder()
|
|
.build(&env::var("DATABASE_URL").unwrap())
|
|
.await?,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl TypeMapKey for DbConnPool {
|
|
type Value = Self;
|
|
}
|