@@ -4,6 +4,7 @@ use futures::{FutureExt, TryFutureExt};
44use neb:: client:: transaction:: { Transaction , TxnError } ;
55use neb:: ram:: cell:: OwnedCell ;
66use neb:: ram:: types:: Id ;
7+ use std:: future;
78use std:: sync:: Arc ;
89
910use super :: super :: id_list:: IdList ;
@@ -37,50 +38,70 @@ pub trait BilateralEdge: TEdge + Sync + Send {
3738 txn : & ' a Transaction ,
3839 id : Id ,
3940 ) -> BoxFuture < ' a , Result < Result < Self :: Edge , EdgeError > , TxnError > > {
40- txn. read ( id)
41- . map_ok ( move |trace_cell| {
42- let trace_cell = match trace_cell {
43- Some ( cell) => cell,
44- None => return Err ( EdgeError :: CellNotFound ) ,
45- } ;
46- let cell_schema_type = match schemas. schema_type ( trace_cell. header . schema ) {
47- Some ( t) => t,
48- None => return Err ( EdgeError :: CannotFindSchema ) ,
49- } ;
50- let mut a_id = Id :: unit_id ( ) ;
51- let mut b_id = Id :: unit_id ( ) ;
52- let edge_cell = match cell_schema_type {
53- GraphSchema :: Vertex => {
54- if vertex_field == Self :: vertex_a_field ( ) {
55- a_id = vertex_id;
56- b_id = id;
57- } else if vertex_field == Self :: vertex_b_field ( ) {
58- b_id = vertex_id;
59- a_id = id;
60- } else {
61- return Err ( EdgeError :: WrongVertexField ) ;
62- }
63- None
64- }
65- GraphSchema :: Edge ( edge_attrs) => {
66- if edge_attrs. edge_type == Self :: edge_type ( ) {
67- if let ( & OwnedValue :: Id ( e_a_id) , & OwnedValue :: Id ( e_b_id) ) = (
68- & trace_cell. data [ Self :: edge_a_field ( ) ] ,
69- & trace_cell. data [ Self :: edge_b_field ( ) ] ,
70- ) {
71- a_id = e_a_id;
72- b_id = e_b_id;
41+ // println!("getting edge from id: {:?}, schema_id: {:?}", id, schema_id);
42+ let edge_schema = schemas. schema_type ( schema_id) . unwrap ( ) ;
43+ if let GraphSchema :: Edge ( edge_attrs) = edge_schema {
44+ if edge_attrs. has_body {
45+ return txn
46+ . read ( id)
47+ . map_ok ( move |trace_cell| {
48+ println ! ( "trace_cell: {:?}" , trace_cell) ;
49+ let trace_cell = match trace_cell {
50+ Some ( cell) => cell,
51+ None => return Err ( EdgeError :: CellNotFound ) ,
52+ } ;
53+ let cell_schema_type = match schemas. schema_type ( trace_cell. header . schema ) {
54+ Some ( t) => t,
55+ None => return Err ( EdgeError :: CannotFindSchema ) ,
56+ } ;
57+ let mut a_id = Id :: unit_id ( ) ;
58+ let mut b_id = Id :: unit_id ( ) ;
59+ let edge_cell = match cell_schema_type {
60+ GraphSchema :: Vertex => {
61+ if vertex_field == Self :: vertex_a_field ( ) {
62+ a_id = vertex_id;
63+ b_id = id;
64+ } else if vertex_field == Self :: vertex_b_field ( ) {
65+ b_id = vertex_id;
66+ a_id = id;
67+ } else {
68+ return Err ( EdgeError :: WrongVertexField ) ;
69+ }
70+ None
7371 }
74- Some ( trace_cell)
75- } else {
76- return Err ( EdgeError :: WrongEdgeType ) ;
77- }
78- }
79- _ => return Err ( EdgeError :: WrongSchema ) ,
80- } ;
81- Ok ( Self :: build_edge ( a_id, b_id, schema_id, edge_cell) )
82- } )
72+ GraphSchema :: Edge ( edge_attrs) => {
73+ if edge_attrs. edge_type == Self :: edge_type ( ) {
74+ if let ( & OwnedValue :: Id ( e_a_id) , & OwnedValue :: Id ( e_b_id) ) = (
75+ & trace_cell. data [ Self :: edge_a_field ( ) ] ,
76+ & trace_cell. data [ Self :: edge_b_field ( ) ] ,
77+ ) {
78+ a_id = e_a_id;
79+ b_id = e_b_id;
80+ }
81+ Some ( trace_cell)
82+ } else {
83+ return Err ( EdgeError :: WrongEdgeType ) ;
84+ }
85+ }
86+ _ => return Err ( EdgeError :: WrongSchema ) ,
87+ } ;
88+ Ok ( Self :: build_edge ( a_id, b_id, schema_id, edge_cell) )
89+ } )
90+ . boxed ( ) ;
91+ } else {
92+ let a_id = vertex_id;
93+ let b_id = id;
94+ async move {
95+ Ok ( Ok ( Self :: build_edge ( a_id, b_id, schema_id, None ) ) )
96+ }
97+ . boxed ( )
98+ }
99+ } else {
100+ async move {
101+ Ok ( Err ( EdgeError :: WrongSchema ) )
102+ }
83103 . boxed ( )
104+ }
84105 }
85106
86107 fn link < ' a > (
0 commit comments