2020-12-24 16:24:04 +01:00
|
|
|
#![recursion_limit = "256"]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
|
2021-04-16 15:20:25 +02:00
|
|
|
use actix::{Actor, SyncContext};
|
|
|
|
use diesel::pg::PgConnection;
|
|
|
|
use diesel::r2d2::{self, ConnectionManager};
|
2020-12-24 16:24:04 +01:00
|
|
|
pub use errors::*;
|
|
|
|
|
|
|
|
pub mod authorize_user;
|
|
|
|
pub mod comments;
|
|
|
|
pub mod epics;
|
|
|
|
pub mod errors;
|
|
|
|
pub mod invitations;
|
|
|
|
pub mod issue_assignees;
|
|
|
|
pub mod issue_statuses;
|
|
|
|
pub mod issues;
|
|
|
|
pub mod messages;
|
|
|
|
pub mod models;
|
|
|
|
pub mod prelude;
|
|
|
|
pub mod projects;
|
|
|
|
pub mod schema;
|
|
|
|
pub mod tokens;
|
|
|
|
pub mod user_projects;
|
2021-04-25 11:31:52 +02:00
|
|
|
pub mod user_settings;
|
2020-12-24 16:24:04 +01:00
|
|
|
pub mod users;
|
|
|
|
|
|
|
|
pub type DbPool = r2d2::Pool<ConnectionManager<PgConnection>>;
|
|
|
|
pub type DbPooledConn = r2d2::PooledConnection<ConnectionManager<PgConnection>>;
|
|
|
|
|
|
|
|
pub struct DbExecutor {
|
|
|
|
pub pool: DbPool,
|
2023-03-31 23:25:20 +02:00
|
|
|
pub config: bitque_config::database::Configuration,
|
2020-12-24 16:24:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Actor for DbExecutor {
|
|
|
|
type Context = SyncContext<Self>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DbExecutor {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
pool: build_pool(),
|
2023-03-31 23:25:20 +02:00
|
|
|
config: bitque_config::database::Configuration::read(),
|
2020-12-24 16:24:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build_pool() -> DbPool {
|
|
|
|
dotenv::dotenv().ok();
|
2023-03-31 23:25:20 +02:00
|
|
|
let config = bitque_config::database::Configuration::read();
|
2020-12-24 16:24:04 +01:00
|
|
|
|
2021-10-05 14:34:20 +02:00
|
|
|
let manager = ConnectionManager::<PgConnection>::new(&config.database_url);
|
2020-12-24 16:24:04 +01:00
|
|
|
r2d2::Pool::builder()
|
|
|
|
.max_size(config.concurrency as u32)
|
|
|
|
.build(manager)
|
|
|
|
.unwrap_or_else(|e| panic!("Failed to create pool. {}", e))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait SyncQuery {
|
|
|
|
type Result;
|
|
|
|
|
|
|
|
fn handle(&self, pool: &DbPool) -> Self::Result;
|
|
|
|
}
|