diff --git a/src/database/mod.rs b/src/database/mod.rs index 5a99b78..42aa35a 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -75,7 +75,7 @@ pub struct OpenResult { pub struct UpEndDatabase { pool: DbPool, pub vault_path: Arc, - pub db_path: Arc + pub db_path: Arc, } pub const UPEND_SUBDIR: &str = ".upend"; @@ -116,7 +116,7 @@ impl UpEndDatabase { let db = UpEndDatabase { pool, vault_path: Arc::new(PathBuf::from(dirpath.as_ref())), - db_path: Arc::new(upend_path) + db_path: Arc::new(upend_path), }; let connection = db.connection().unwrap(); @@ -336,6 +336,19 @@ impl UpEndConnection { Ok(Address::Hash(entry.hash()?)) } + + // #[deprecated] + pub fn get_all_attributes(&self) -> Result> { + use crate::database::inner::schema::data::dsl::*; + + let result = data + .select(attribute) + .distinct() + .order_by(attribute) + .load::(&self.conn)?; + + Ok(result) + } } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index 43b91f6..3316726 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,6 +155,7 @@ fn main() -> Result<()> { .service(routes::get_object) .service(routes::put_object) .service(routes::delete_object) + .service(routes::get_all_attributes) .service(routes::api_refresh) .service(routes::list_hier) .service(routes::list_hier_roots) diff --git a/src/routes.rs b/src/routes.rs index f24db0d..c19aadd 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -217,6 +217,13 @@ pub async fn delete_object( Ok(HttpResponse::Ok().finish()) } +#[get("/api/all/attributes")] +pub async fn get_all_attributes(state: web::Data) -> Result { + let connection = state.upend.connection().map_err(ErrorInternalServerError)?; + let result = connection.get_all_attributes().map_err(ErrorInternalServerError)?; + Ok(HttpResponse::Ok().json(result)) +} + #[get("/api/hier/{path:.*}")] pub async fn list_hier( state: web::Data,