surrealdb_core/sql/
edges.rs1use crate::sql::dir::Dir;
2use crate::sql::table::Tables;
3use crate::sql::thing::Thing;
4use revision::revisioned;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Edges";
9
10#[revisioned(revision = 1)]
11#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
12#[serde(rename = "$surrealdb::private::sql::Edges")]
13#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
14#[non_exhaustive]
15pub struct Edges {
16 pub dir: Dir,
17 pub from: Thing,
18 pub what: Tables,
19}
20
21impl Edges {
22 pub fn new(dir: Dir, from: Thing, what: Tables) -> Self {
23 Edges {
24 dir,
25 from,
26 what,
27 }
28 }
29}
30
31impl fmt::Display for Edges {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 match self.what.len() {
34 0 => write!(f, "{}{}?", self.from, self.dir,),
35 1 => write!(f, "{}{}{}", self.from, self.dir, self.what),
36 _ => write!(f, "{}{}({})", self.from, self.dir, self.what),
37 }
38 }
39}