Trait aragog::EdgeRecord[][src]

pub trait EdgeRecord: Record {
    fn _from(&self) -> &String;
fn _to(&self) -> &String; fn _from_key(&self) -> String { ... }
fn _to_key(&self) -> String { ... }
fn _to_collection_name(&self) -> String { ... }
fn _from_collection_name(&self) -> String { ... } }

Trait for structures that can be stored in Database as a ArangoDB EdgeCollection. The trait must be implemented to be used as a edge record in DatabaseRecord.

How to use

Declaration

A structure deriving from EdgeRecord MUST contain two string fields:

  • _from - The id of the source document
  • _to - The id of the target document Or the compilation will fail.

On creation or save these two fields must be valid ArangoDB Object ID formatted as:

CollectionName/DocumentKey

(Example: "User/123") >

Creation

To create a edge between two existing DatabaseRecord you can use the following process:

#[derive(Clone, Record, Serialize, Deserialize)]
struct Character {}

#[derive(Clone, EdgeRecord, Record, Serialize, Deserialize)]
struct Edge {
    _from: String,
    _to: String,
    description: String,
}

let record_a = Character::find("123", &db_accessor).await.unwrap();
let record_b = Character::find("234", &db_accessor).await.unwrap();

let edge_record = DatabaseRecord::link(&record_a, &record_b, &db_accessor, |_from, _to| {
    Edge { _from, _to, description: "description".to_string() }
}).await.unwrap();

Required methods

fn _from(&self) -> &String[src]

Retrieves the struct _from field

fn _to(&self) -> &String[src]

Retrieves the struct _to field

Loading content...

Provided methods

fn _from_key(&self) -> String[src]

Parses the _from() returned id and returns the document key

Panic

The method will panic if the stored id is not formatted correctly (String/String)

Example

 use aragog::{EdgeRecord, Record, Validate, DatabaseRecord};

 #[derive(EdgeRecord, Record, Clone, Serialize, Deserialize, Validate)]
 struct EdgeModel {
     pub _from: String,
     pub _to: String,
 }

 let edge = EdgeModel {
    _from: "User/123".to_string(),
    _to: "Client/345".to_string(),
 };
 assert_eq!(edge._from_key(), "123".to_string());

fn _to_key(&self) -> String[src]

Parses the _to() returned id and returns the document key

Panic

The method will panic if the stored id is not formatted correctly (String/String)

Example

 use aragog::{EdgeRecord, Record, Validate, DatabaseRecord};

 #[derive(EdgeRecord, Record, Clone, Serialize, Deserialize, Validate)]
 struct EdgeModel {
     pub _from: String,
     pub _to: String,
 }

 let edge = EdgeModel {
    _from: "User/123".to_string(),
    _to: "Client/345".to_string(),
 };
 assert_eq!(edge._to_key(), "345".to_string());

fn _to_collection_name(&self) -> String[src]

Parses the _to() returned id and returns the document collection name

Panic

The method will panic if the stored id is not formatted correctly (String/String)

Example

 use aragog::{EdgeRecord, Record, Validate, DatabaseRecord};

 #[derive(EdgeRecord, Record, Clone, Serialize, Deserialize, Validate)]
 struct EdgeModel {
     pub _from: String,
     pub _to: String,
 }

 let edge = EdgeModel {
    _from: "User/123".to_string(),
    _to: "Client/345".to_string(),
 };
 assert_eq!(edge._to_collection_name(), "Client".to_string());

fn _from_collection_name(&self) -> String[src]

Parses the _from() returned id and returns the document collection name

Panic

The method will panic if the stored id is not formatted correctly (String/String)

Example

 use aragog::{EdgeRecord, Record, Validate, DatabaseRecord};

 #[derive(EdgeRecord, Record, Clone, Serialize, Deserialize, Validate)]
 struct EdgeModel {
     pub _from: String,
     pub _to: String,
 }

 let edge = EdgeModel {
    _from: "User/123".to_string(),
    _to: "Client/345".to_string(),
 };
 assert_eq!(edge._from_collection_name(), "User".to_string());
Loading content...

Implementors

Loading content...