arangors/
graph.rs

1//! This module facilitates the building of new named graphs as well as the
2//! retrieval of existing indexes in ArangoDB.
3//!
4//! The various structures are following the HTTP specification as detailed in
5//! this ArangoDB [section](https://www.arangodb.com/docs/stable/http/gharial-management.html)
6//!
7//! For detailed information about ArangoDB named graphs, please check out the
8//! official ArangoDB [documentation](https://www.arangodb.com/docs/stable/http/gharial.html).
9use serde::{Deserialize, Serialize};
10use typed_builder::TypedBuilder;
11
12pub(crate) const GHARIAL_API_PATH: &str = "_api/gharial";
13
14/// Represents a Named Graph in ArangoDB.
15#[derive(Debug, Clone, Serialize, Deserialize, Default, TypedBuilder)]
16#[serde(rename_all = "camelCase")]
17pub struct Graph {
18    /// Name of the graph
19    #[builder(default)]
20    pub name: String,
21    /// An array of definitions for the relations of the graph.
22    #[builder(default)]
23    pub edge_definitions: Vec<EdgeDefinition>,
24    /// An array of additional vertex collections. Documents within these
25    /// collections do not have edges within this graph.
26    #[builder(default)]
27    #[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
28    pub orphan_collections: Vec<String>,
29    /// Define if the created graph should be smart (Enterprise Edition only).
30    #[builder(default)]
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub is_smart: Option<bool>,
33    /// Whether to create a Disjoint SmartGraph instead of a regular SmartGraph
34    /// (Enterprise Edition only).
35    #[builder(default)]
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub is_disjoint: Option<bool>,
38    /// a JSON object to define options for creating collections within this
39    /// graph.
40    #[builder(default)]
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub options: Option<GraphOptions>,
43}
44
45/// Represents the available options for a [`Graph`] Creation
46///
47/// [`Graph`]: struct.Graph.html
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50pub struct GraphOptions {
51    /// Only has effect in Enterprise Edition and it is required if isSmart is
52    /// true. The attribute name that is used to smartly shard the vertices
53    /// of a graph. Every vertex in this SmartGraph has to have this
54    /// attribute. Cannot be modified later.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub smart_graph_attribute: Option<String>,
57    /// The number of shards that is used for every collection within this
58    /// graph. Cannot be modified later.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub number_of_shards: Option<u32>,
61    /// The replication factor used when initially creating collections for this
62    /// graph. Can be set to "satellite" to create a SatelliteGraph, which
63    /// will ignore numberOfShards, minReplicationFactor and writeConcern
64    /// (Enterprise Edition only).
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub replication_factor: Option<u32>,
67    /// Write concern for new collections in the graph.
68    /// It determines how many copies of each shard are required to be in sync
69    /// on the different DB-Servers. If there are less then these many
70    /// copies in the cluster a shard will refuse to write. Writes to shards
71    /// with enough up-to-date copies will succeed at the same time however.
72    /// The value of writeConcern can not be larger than replicationFactor.
73    /// (cluster only)
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub write_concern: Option<u32>,
76}
77
78/// Represents one Edge definition for a [`Graph`] Creation.
79///
80/// [`Graph`]: struct.Graph.html
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct EdgeDefinition {
84    /// Name of the edge collection
85    pub collection: String,
86    /// List of the `_from` collection names
87    pub from: Vec<String>,
88    /// List of the `_to` collection names
89    pub to: Vec<String>,
90}
91
92/// Represents a collection of [`Graphs`] on a database in ArangoDB.
93///
94/// [`Graphs`]: struct.Graph.html
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct GraphCollection {
98    pub graphs: Vec<Graph>,
99}
100
101/// Represents a [`Graph`] as returned by ArangoDB after a HTTP retrieval
102///
103/// [`Graph`]: struct.Graph.html
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(rename_all = "camelCase")]
106pub struct GraphResponse {
107    pub graph: Graph,
108}