bolt_proto/value/
relationship.rs

1use std::collections::HashMap;
2
3use bolt_proto_derive::*;
4
5use crate::{value::SIGNATURE_RELATIONSHIP, Value};
6
7#[bolt_structure(SIGNATURE_RELATIONSHIP)]
8#[derive(Debug, Clone, Eq, PartialEq)]
9pub struct Relationship {
10    pub(crate) rel_identity: i64,
11    pub(crate) start_node_identity: i64,
12    pub(crate) end_node_identity: i64,
13    pub(crate) rel_type: String,
14    pub(crate) properties: HashMap<String, Value>,
15}
16
17impl Relationship {
18    pub fn new(
19        rel_identity: i64,
20        start_node_identity: i64,
21        end_node_identity: i64,
22        rel_type: String,
23        properties: HashMap<String, impl Into<Value>>,
24    ) -> Self {
25        Self {
26            rel_identity,
27            start_node_identity,
28            end_node_identity,
29            rel_type,
30            properties: properties.into_iter().map(|(k, v)| (k, v.into())).collect(),
31        }
32    }
33
34    pub fn rel_identity(&self) -> i64 {
35        self.rel_identity
36    }
37
38    pub fn start_node_identity(&self) -> i64 {
39        self.start_node_identity
40    }
41
42    pub fn end_node_identity(&self) -> i64 {
43        self.end_node_identity
44    }
45
46    pub fn rel_type(&self) -> &str {
47        &self.rel_type
48    }
49
50    pub fn properties(&self) -> &HashMap<String, Value> {
51        &self.properties
52    }
53}