Skip to content

Commit

Permalink
feat: Graph Options correction, Clone Implementation on public structs (
Browse files Browse the repository at this point in the history
#51)

* public database structs now implement Clone

* Fixing wrong Graph option types
  • Loading branch information
ManevilleF committed Dec 20, 2020
1 parent 965ba42 commit a669281
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ By now, the available features of arangors are:
- (WIP) Milestone 1.0.x

Provides the API related to:
- [X] Graph Management
- [X] Index Management
- [ ] User Management
- (X) Graph Management
- (X) Index Management
- ( ) User Management

In this stage, all operations available for database, collection and
document should be implemented.
Expand Down
14 changes: 7 additions & 7 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use typed_builder::TypedBuilder;
pub(crate) const GHARIAL_API_PATH: &str = "_api/gharial";

/// Represents a Named Graph in ArangoDB.
#[derive(Debug, Serialize, Deserialize, Default, TypedBuilder)]
#[derive(Debug, Clone, Serialize, Deserialize, Default, TypedBuilder)]
#[serde(rename_all = "camelCase")]
pub struct Graph {
/// Name of the graph
Expand Down Expand Up @@ -42,17 +42,17 @@ pub struct Graph {
/// Represents the available options for a [`Graph`] Creation
///
/// [`Graph`]: struct.Graph.html
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphOptions {
/// Only has effect in Enterprise Edition and it is required if isSmart is true.
/// The attribute name that is used to smartly shard the vertices of a graph.
/// Every vertex in this SmartGraph has to have this attribute. Cannot be modified later.
#[serde(skip_serializing_if = "Option::is_none")]
pub smart_graph_attribute: Option<bool>,
pub smart_graph_attribute: Option<String>,
/// The number of shards that is used for every collection within this graph. Cannot be modified later.
#[serde(skip_serializing_if = "Option::is_none")]
pub number_of_shards: Option<bool>,
pub number_of_shards: Option<u32>,
/// The replication factor used when initially creating collections for this graph.
/// Can be set to "satellite" to create a SatelliteGraph, which will ignore numberOfShards,
/// minReplicationFactor and writeConcern (Enterprise Edition only).
Expand All @@ -70,7 +70,7 @@ pub struct GraphOptions {
/// Represents one Edge definition for a [`Graph`] Creation.
///
/// [`Graph`]: struct.Graph.html
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EdgeDefinition {
/// Name of the edge collection
Expand All @@ -84,7 +84,7 @@ pub struct EdgeDefinition {
/// Represents a collection of [`Graphs`] on a database in ArangoDB.
///
/// [`Graphs`]: struct.Graph.html
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphCollection {
pub graphs: Vec<Graph>,
Expand All @@ -93,7 +93,7 @@ pub struct GraphCollection {
/// Represents a [`Graph`] as returned by ArangoDB after a HTTP retrieval
///
/// [`Graph`]: struct.Graph.html
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphResponse {
pub graph: Graph,
Expand Down
8 changes: 5 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
//! * Skiplist
//! * Ttl (Time to live)
//!
//! An index of type [`Primary`] cannot be created and is only available for
//! An index of type [Primary] cannot be created and is only available for
//! the retrieval of existing indexes, as ArangoDB creates a primary index on
//! every collection.
//! For detailed information about ArangoDB indexes, please check out the
//! official ArangoDB [documentation](https://www.arangodb.com/docs/stable/http/indexes.html).
//!
//! [Primary]: https://www.arangodb.com/docs/stable/http/indexes.html#primary-index
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

Expand Down Expand Up @@ -63,7 +65,7 @@ pub(crate) const INDEX_API_PATH: &str = "_api/index";
/// ```
/// [`Index`]: struct.Index.html
/// [`settings`]: enum.IndexSettings.html
#[derive(Debug, Serialize, Deserialize, Default, TypedBuilder)]
#[derive(Debug, Clone, Serialize, Deserialize, Default, TypedBuilder)]
#[serde(rename_all = "camelCase")]
pub struct Index {
#[builder(default)]
Expand All @@ -85,7 +87,7 @@ pub struct Index {

/// Settings for the different index types. This `enum` also sets the index
/// type.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum IndexSettings {
Primary {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
//! - (WIP) Milestone 1.0.x
//!
//! Provides the API related to:
//! - [X] Graph Management
//! - [X] Index Management
//! - [ ] User Management
//! - (X) Graph Management
//! - (X) Index Management
//! - ( ) User Management
//!
//! In this stage, all operations available for database, collection and
//! document should be implemented.
Expand Down
45 changes: 45 additions & 0 deletions tests/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,51 @@ async fn test_simple_graph() {
assert!(result.options.is_none());
}

#[maybe_async::test(
any(feature = "reqwest_blocking"),
async(any(feature = "reqwest_async"), tokio::test),
async(any(feature = "surf_async"), async_std::test)
)]
async fn test_complex_graph() {
test_setup();
let conn = connection().await;

let database = conn.db("test_db").await.unwrap();
// Cleanup
drop_graph(&database, "test_complex_graph").await;

let graph = Graph::builder()
.name("test_complex_graph".to_string())
.edge_definitions(vec![EdgeDefinition {
collection: "some_edge".to_string(),
from: vec!["from_collection".to_string()],
to: vec!["to_collection".to_string()],
}])
.orphan_collections(vec!["some_collection".to_string()])
.is_smart(Some(true))
.is_disjoint(Some(false))
.options(Some(GraphOptions {
smart_graph_attribute: Some("region".to_string()),
number_of_shards: Some(2),
replication_factor: Some(10),
write_concern: Some(8),
}))
.build();
let result = database.create_graph(graph, true).await.unwrap();
assert_eq!(result.name, "test_complex_graph".to_string());
assert_eq!(result.orphan_collections.len(), 1);
// Would work only with Enterprise Edition
//
// assert_eq!(result.is_disjoint.unwrap(), false);
// assert_eq!(result.is_smart.unwrap(), true);
// assert!(result.options.is_some());
// let options = result.options.unwrap();
// assert_eq!(options.number_of_shards.unwrap(), 2);
// assert_eq!(options.replication_factor.unwrap(),10);
// assert_eq!(options.write_concern.unwrap(), 8);
// assert_eq!(options.smart_graph_attribute.unwrap(), "region".to_string());
}

#[maybe_async::test(
any(feature = "reqwest_blocking"),
async(any(feature = "reqwest_async"), tokio::test),
Expand Down

0 comments on commit a669281

Please sign in to comment.