aragog/schema/
graph_schema.rs

1use crate::schema::SchemaDatabaseOperation;
2use arangors_lite::graph::Graph;
3use arangors_lite::{ClientError, Database};
4use serde::{Deserialize, Serialize};
5
6/// Aragog schema representation of an `ArangoDB` Named Graph.
7/// This struct is meant to load/generate the schema file.
8#[derive(Debug, Serialize, Deserialize, Clone)]
9pub struct GraphSchema(pub Graph);
10
11impl From<GraphSchema> for Graph {
12    fn from(schema: GraphSchema) -> Self {
13        schema.0
14    }
15}
16
17#[maybe_async::maybe_async]
18impl SchemaDatabaseOperation for GraphSchema {
19    type PoolType = Graph;
20
21    async fn apply_to_database(
22        &self,
23        database: &Database,
24        silent: bool,
25    ) -> Result<Option<Self::PoolType>, ClientError> {
26        log::debug!("Creating Graph {}", &self.0.name);
27        let graph = self.clone().into();
28        Self::handle_pool_result(database.create_graph(graph, true).await, silent)
29    }
30
31    async fn drop(&self, database: &Database) -> Result<(), ClientError> {
32        log::debug!("Deleting Graph {}", &self.0.name);
33        database.drop_graph(&self.0.name, false).await?;
34        Ok(())
35    }
36
37    async fn get(&self, database: &Database) -> Result<Self::PoolType, ClientError> {
38        database.graph(&self.0.name).await
39    }
40}