@@ -362,14 +362,12 @@ impl ExportContext {
362362 rel_type = rel_spec. rel_type,
363363 } ;
364364
365- let analyzed_src = analyzed_data_coll
366- . source
365+ let analyzed_rel = analyzed_data_coll
366+ . rel
367367 . as_ref ( )
368- . ok_or_else ( || anyhow ! ( "Relationship spec requires source fields" ) ) ?;
369- let analyzed_tgt = analyzed_data_coll
370- . target
371- . as_ref ( )
372- . ok_or_else ( || anyhow ! ( "Relationship spec requires target fields" ) ) ?;
368+ . ok_or_else ( invariance_violation) ?;
369+ let analyzed_src = & analyzed_rel. source ;
370+ let analyzed_tgt = & analyzed_rel. target ;
373371
374372 let ( src_key_field_params, src_key_fields_literal) =
375373 Self :: build_key_field_params_n_literal (
@@ -475,57 +473,41 @@ impl ExportContext {
475473 }
476474
477475 let value = & upsert. value ;
478- let mut insert_cypher =
476+ let mut query =
479477 self . bind_rel_key_field_params ( neo4rs:: query ( & self . insert_cypher ) , & upsert. key ) ?;
480478
481- if let Some ( analyzed_src) = & self . analyzed_data_coll . source {
482- insert_cypher = Self :: bind_key_field_params (
483- insert_cypher,
484- & self . src_key_field_params ,
485- std:: iter:: zip (
486- analyzed_src. schema . key_fields . iter ( ) ,
487- analyzed_src. fields_input_idx . key . iter ( ) ,
488- )
489- . map ( |( f, field_idx) | ( & f. value_type . typ , & value. fields [ * field_idx] ) ) ,
490- ) ?;
491-
492- if analyzed_src. has_value_fields ( ) {
493- insert_cypher = insert_cypher. param (
494- SRC_PROPS_PARAM ,
495- mapped_field_values_to_bolt (
496- & analyzed_src. schema . value_fields ,
497- & analyzed_src. fields_input_idx . value ,
498- value,
499- ) ?,
500- ) ;
501- }
502- }
503-
504- if let Some ( analyzed_tgt) = & self . analyzed_data_coll . target {
505- insert_cypher = Self :: bind_key_field_params (
506- insert_cypher,
507- & self . tgt_key_field_params ,
508- std:: iter:: zip (
509- analyzed_tgt. schema . key_fields . iter ( ) ,
510- analyzed_tgt. fields_input_idx . key . iter ( ) ,
511- )
512- . map ( |( f, field_idx) | ( & f. value_type . typ , & value. fields [ * field_idx] ) ) ,
513- ) ?;
514-
515- if analyzed_tgt. has_value_fields ( ) {
516- insert_cypher = insert_cypher. param (
517- TGT_PROPS_PARAM ,
518- mapped_field_values_to_bolt (
519- & analyzed_tgt. schema . value_fields ,
520- & analyzed_tgt. fields_input_idx . value ,
521- value,
522- ) ?,
523- ) ;
524- }
479+ if let Some ( analyzed_rel) = & self . analyzed_data_coll . rel {
480+ let bind_params = |query : neo4rs:: Query ,
481+ analyzed : & AnalyzedGraphElementFieldMapping ,
482+ key_field_params : & [ String ] |
483+ -> Result < neo4rs:: Query > {
484+ let mut query = Self :: bind_key_field_params (
485+ query,
486+ key_field_params,
487+ std:: iter:: zip (
488+ analyzed. schema . key_fields . iter ( ) ,
489+ analyzed. fields_input_idx . key . iter ( ) ,
490+ )
491+ . map ( |( f, field_idx) | ( & f. value_type . typ , & value. fields [ * field_idx] ) ) ,
492+ ) ?;
493+ if analyzed. has_value_fields ( ) {
494+ query = query. param (
495+ SRC_PROPS_PARAM ,
496+ mapped_field_values_to_bolt (
497+ & analyzed. schema . value_fields ,
498+ & analyzed. fields_input_idx . value ,
499+ value,
500+ ) ?,
501+ ) ;
502+ }
503+ Ok ( query)
504+ } ;
505+ query = bind_params ( query, & analyzed_rel. source , & self . src_key_field_params ) ?;
506+ query = bind_params ( query, & analyzed_rel. target , & self . tgt_key_field_params ) ?;
525507 }
526508
527509 if !self . analyzed_data_coll . value_fields_input_idx . is_empty ( ) {
528- insert_cypher = insert_cypher . param (
510+ query = query . param (
529511 CORE_PROPS_PARAM ,
530512 mapped_field_values_to_bolt (
531513 & self . analyzed_data_coll . schema . value_fields ,
@@ -534,7 +516,7 @@ impl ExportContext {
534516 ) ?,
535517 ) ;
536518 }
537- queries. push ( insert_cypher ) ;
519+ queries. push ( query ) ;
538520 Ok ( ( ) )
539521 }
540522
0 commit comments