chimney 0.1.0

Simple rust based FHIR resource store.
Documentation
use std::fmt;
use indradb::ValidationError;
use uuid::Uuid;
use anyhow::{Result, Context};

pub struct ChimneyStore {
    db: indradb::Database<indradb::MemoryDatastore>,
}

impl ChimneyStore{
    pub fn new(db: indradb::Database<indradb::MemoryDatastore>) -> Self { Self { db } }

    pub fn get_db(&self) -> &indradb::Database<indradb::MemoryDatastore> { &self.db }

    pub fn get_db_mut(&mut self) -> &mut indradb::Database<indradb::MemoryDatastore> { &mut self.db }

    pub fn get_datastore(&self) -> &indradb::MemoryDatastore { &self.db.datastore }

    pub fn get_datastore_mut(&mut self) -> &mut indradb::MemoryDatastore { &mut self.db.datastore }

    pub fn add_vertex(&mut self) -> Result<indradb::Vertex> {
        let id = self.make_id().context("Failed to create ID")?;
        let vertex = indradb::Vertex::new(id);
        self.db.create_vertex(&vertex).context("Failed to add vertex")?;
        Ok(vertex)

    }

    fn make_id(&self) -> Result<indradb::Identifier, ValidationError> {
        let uuid = Uuid::new_v4();
        indradb::Identifier::new(uuid.to_string())
    }




}

impl fmt::Debug for ChimneyStore {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Store")
            .field("db", &self.db.datastore)
            .finish()
    }
}