commit 8cec55ee21419f88c178e3af4a59f17f37d7458e
parent 9df996d0e4d32b5a47b4ce8d90d86c8ae4306ade
Author: Jackson G. Kaindume <kaindume@kwatafana.org>
Date: Fri, 23 Sep 2022 19:12:38 +0200
[phora] add
Diffstat:
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/phora/src/lib.rs b/phora/src/lib.rs
@@ -7,6 +7,13 @@ pub mod data;
pub mod database;
pub mod endpoints;
pub mod validate;
+/// Cyrtophora configuration
+pub struct CyrtophoraConfig {
+ #[cfg(feature = "sqlite")]
+ /// Path to database
+ pub database_path: String,
+ pub endpoints: Option<Endpoints>,
+}
pub struct Cyrtophora<D>
where
@@ -21,14 +28,20 @@ where
impl<D: DB> Cyrtophora<D> {
#[cfg(feature = "sqlite")]
pub fn new_sqlite(
- db_path: &str,
+ config: CyrtophoraConfig,
) -> Result<Cyrtophora<database::sqlite::SqliteDB>, database::error::Error> {
- let mut db = database::sqlite::SqliteDB::new(db_path);
+ let mut db = database::sqlite::SqliteDB::new(&config.database_path);
db.connect()?;
- let endpoints: Endpoints = Default::default();
+
+ let endpoints = if let Some(e) = config.endpoints {
+ e
+ } else {
+ Endpoints::default()
+ };
+
let c = Cyrtophora {
database: Some(db),
- endpoints: endpoints,
+ endpoints,
};
Ok(c)
}
@@ -75,7 +88,12 @@ mod test {
#[cfg(feature = "sqlite")]
fn test_create_and_get_account_sqlite() {
remove_test_db();
- let mut cyrt = Cyrtophora::<database::sqlite::SqliteDB>::new_sqlite(TEST_DB_PATH).unwrap();
+ let config = CyrtophoraConfig {
+ database_path: TEST_DB_PATH.to_string(),
+ endpoints: None,
+ };
+
+ let mut cyrt = Cyrtophora::<database::sqlite::SqliteDB>::new_sqlite(config).unwrap();
let account_input = crate::data::AccountCreationInput {
username: "testuser".to_string(),
password: "1234567890".to_string(),