2022-04-13 12:20:26 +05:30
|
|
|
/*
|
|
|
|
* ForgeFlux StarChart - A federated software forge spider
|
|
|
|
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
pub use std::sync::Arc;
|
|
|
|
|
2022-05-17 19:57:57 +05:30
|
|
|
use crate::ctx::Ctx;
|
2022-04-13 12:20:26 +05:30
|
|
|
pub use crate::db::BoxDB;
|
2022-05-18 17:39:53 +05:30
|
|
|
pub use crate::federate::{get_federate, ArcFederate};
|
2022-04-13 12:20:26 +05:30
|
|
|
use crate::settings::{DBType, Settings};
|
|
|
|
|
|
|
|
//pub mod sqlx_postgres {
|
|
|
|
// use super::*;
|
|
|
|
//
|
2022-05-17 19:57:57 +05:30
|
|
|
// pub async fn get_ctx() -> (BoxDB, Arc<Ctx>) {
|
2022-04-13 12:20:26 +05:30
|
|
|
// let url = env::var("POSTGRES_DATABASE_URL").unwrap();
|
|
|
|
// let mut settings = Settings::new().unwrap();
|
|
|
|
// settings.database.url = url.clone();
|
|
|
|
// settings.database.database_type = DBType::Postgres;
|
|
|
|
// let db = pg::get_data(Some(settings.clone())).await;
|
2022-05-17 19:57:57 +05:30
|
|
|
// (db, Ctx::new(Some(settings)))
|
2022-04-13 12:20:26 +05:30
|
|
|
// }
|
|
|
|
|
|
|
|
pub mod sqlx_sqlite {
|
|
|
|
use super::*;
|
|
|
|
use crate::db::sqlite;
|
2022-05-17 20:12:30 +05:30
|
|
|
use mktemp::Temp;
|
2022-04-13 12:20:26 +05:30
|
|
|
|
2022-05-18 17:39:53 +05:30
|
|
|
pub async fn get_ctx() -> (BoxDB, Arc<Ctx>, ArcFederate, Temp) {
|
2022-04-13 12:20:26 +05:30
|
|
|
let url = env::var("SQLITE_DATABASE_URL").unwrap();
|
2022-05-05 00:49:23 +05:30
|
|
|
env::set_var("DATABASE_URL", &url);
|
2022-04-13 12:20:26 +05:30
|
|
|
println!("found db url: {url}");
|
|
|
|
let mut settings = Settings::new().unwrap();
|
|
|
|
settings.database.url = url.clone();
|
|
|
|
settings.database.database_type = DBType::Sqlite;
|
|
|
|
let db = sqlite::get_data(Some(settings.clone())).await;
|
2022-05-17 20:12:30 +05:30
|
|
|
|
|
|
|
let tmp_dir = Temp::new_dir().unwrap();
|
|
|
|
settings.repository.root = tmp_dir.to_str().unwrap().to_string();
|
|
|
|
let federate = get_federate(Some(settings.clone())).await;
|
|
|
|
|
|
|
|
(db, Ctx::new(settings).await, federate, tmp_dir)
|
2022-04-13 12:20:26 +05:30
|
|
|
}
|
|
|
|
}
|