2021-10-03 20:03:32 +00:00
|
|
|
use crate::config::GeoffreyAPIConfig;
|
2022-01-07 02:26:14 +00:00
|
|
|
use crate::{Args, Result};
|
2021-10-03 20:03:32 +00:00
|
|
|
use geoffrey_db::database::Database;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub struct Context {
|
|
|
|
pub db: Database,
|
|
|
|
pub cfg: GeoffreyAPIConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Context {
|
2022-01-07 02:26:14 +00:00
|
|
|
pub fn new(cfg: GeoffreyAPIConfig, args: Args) -> Result<Arc<Self>> {
|
2021-10-03 20:03:32 +00:00
|
|
|
let ctx = Self {
|
2022-01-08 19:35:55 +00:00
|
|
|
db: Database::new(cfg.server_config.db_path.as_path(), args.force_migration).unwrap(),
|
2021-10-03 20:03:32 +00:00
|
|
|
cfg,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Arc::new(ctx))
|
|
|
|
}
|
|
|
|
}
|