ruarango/traits/
graph.rs

1// Copyright (c) 2021 ruarango developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9//! `ruarango` graph trait
10
11use crate::{
12    graph::{
13        input::{
14            CreateConfig, CreateEdgeDefConfig, CreateVertexCollConfig, CreateVertexConfig,
15            DeleteConfig, DeleteEdgeDefConfig, DeleteVertexCollConfig, DeleteVertexConfig,
16            EdgeCreateConfig, EdgeDeleteConfig, EdgeReadConfig, EdgeReplaceConfig,
17            EdgeUpdateConfig, ReadConfig, ReadEdgeDefsConfig, ReadVertexCollsConfig,
18            ReadVertexConfig, ReplaceEdgeDefConfig, UpdateVertexConfig,
19        },
20        output::{
21            CreateEdge, DeleteEdge, DeleteVertexMeta, EdgesMeta, GraphMeta, List, ReadEdge,
22            ReadVertexMeta, ReplaceEdge, UpdateEdge, UpdateVertexMeta, VertexColls, VertexMeta,
23        },
24    },
25    ArangoResult,
26};
27use async_trait::async_trait;
28use serde::Serialize;
29
30/// Database Operations
31#[async_trait]
32pub trait Graph {
33    /// List all graphs
34    async fn list(&self) -> ArangoResult<List>;
35    /// Create a graph
36    async fn create(&self, config: CreateConfig) -> ArangoResult<GraphMeta>;
37    /// Read a graph
38    async fn read(&self, config: ReadConfig) -> ArangoResult<GraphMeta>;
39    /// Delete a graph
40    async fn delete(&self, config: DeleteConfig) -> ArangoResult<()>;
41    /// Create an edge definition
42    async fn create_edge_def(&self, config: CreateEdgeDefConfig) -> ArangoResult<GraphMeta>;
43    /// Read the edge definitions for the given graph
44    async fn read_edge_defs(&self, config: ReadEdgeDefsConfig) -> ArangoResult<EdgesMeta>;
45    /// Delete an edge definition
46    async fn delete_edge_def(&self, config: DeleteEdgeDefConfig) -> ArangoResult<GraphMeta>;
47    /// Replace an edge definition
48    async fn replace_edge_def(&self, config: ReplaceEdgeDefConfig) -> ArangoResult<GraphMeta>;
49    /// Create an edge for a graph
50    async fn create_edge(&self, config: EdgeCreateConfig) -> ArangoResult<CreateEdge>;
51    /// Delete an edge from a graph
52    async fn delete_edge(&self, config: EdgeDeleteConfig) -> ArangoResult<DeleteEdge>;
53    /// Read an edge from a graph
54    async fn read_edge(&self, config: EdgeReadConfig) -> ArangoResult<ReadEdge>;
55    /// Update an edge from a graph
56    async fn update_edge<T>(&self, config: EdgeUpdateConfig<T>) -> ArangoResult<UpdateEdge>
57    where
58        T: Serialize + Send + Sync;
59    /// Replace an edge from a graph
60    async fn replace_edge<T>(&self, config: EdgeReplaceConfig<T>) -> ArangoResult<ReplaceEdge>
61    where
62        T: Serialize + Send + Sync;
63
64    /// Read the vertex collections from a graph
65    async fn read_vertex_colls(&self, config: ReadVertexCollsConfig) -> ArangoResult<VertexColls>;
66    /// Create vertex collection
67    async fn create_vertex_coll(&self, config: CreateVertexCollConfig) -> ArangoResult<GraphMeta>;
68    /// Delete vertex collection
69    async fn delete_vertex_coll(&self, config: DeleteVertexCollConfig) -> ArangoResult<GraphMeta>;
70    /// Create vertex
71    async fn create_vertex<T>(&self, config: CreateVertexConfig<T>) -> ArangoResult<VertexMeta>
72    where
73        T: Serialize + Send + Sync;
74    /// Read a vertex
75    async fn read_vertex(&self, config: ReadVertexConfig) -> ArangoResult<ReadVertexMeta>;
76    /// Delete a vertex
77    async fn delete_vertex(&self, config: DeleteVertexConfig) -> ArangoResult<DeleteVertexMeta>;
78    /// Update vertex
79    async fn update_vertex<T>(
80        &self,
81        config: UpdateVertexConfig<T>,
82    ) -> ArangoResult<UpdateVertexMeta>
83    where
84        T: Serialize + Send + Sync;
85    /// Replace vertex
86    async fn replace_vertex<T>(
87        &self,
88        config: UpdateVertexConfig<T>,
89    ) -> ArangoResult<UpdateVertexMeta>
90    where
91        T: Serialize + Send + Sync;
92}