discord-kurante/src/util/db.rs

27 lines
507 B
Rust
Raw Normal View History

2020-05-02 02:41:29 +00:00
use serenity::prelude::TypeMapKey;
use sqlx::{
sqlite::{SqliteConnection, SqlitePool},
2020-05-02 05:04:51 +00:00
Error, Pool,
2020-05-02 02:41:29 +00:00
};
use std::env;
type DbPool = Pool<SqliteConnection>;
pub(crate) struct DbConnPool {
2020-05-03 03:56:04 +00:00
pub pool: DbPool,
2020-05-02 02:41:29 +00:00
}
impl DbConnPool {
2020-05-02 05:04:51 +00:00
pub async fn new() -> Result<Self, Error> {
Ok(Self {
2020-05-04 23:47:48 +00:00
pool: SqlitePool::builder()
.build(&env::var("DATABASE_URL").unwrap())
.await?,
2020-05-02 05:04:51 +00:00
})
2020-05-02 02:41:29 +00:00
}
}
impl TypeMapKey for DbConnPool {
type Value = Self;
}