github.com/christoph-karpowicz/db_mediator@v0.0.0-20210207102849-61a28a1071d8/internal/server/synch/mapping.go (about)

     1  package synch
     2  
     3  import "github.com/christoph-karpowicz/db_mediator/internal/server/cfg"
     4  
     5  // Mapping represents a single mapping in the config file like:
     6  // example_node1.example_column1 TO example_node2.example_column2
     7  type Mapping struct {
     8  	synch        *Synch
     9  	source       *node
    10  	target       *node
    11  	sourceColumn string
    12  	targetColumn string
    13  	raw          map[string]string
    14  }
    15  
    16  func createMapping(synch *Synch, mapping map[string]string) *Mapping {
    17  
    18  	_, sourceNodeFound := mapping[cfg.PSUBEXP_SOURCE_NODE]
    19  	if !sourceNodeFound {
    20  		panic("[create mapping] ERROR: source node not found.")
    21  	}
    22  	_, targetNodeFound := mapping[cfg.PSUBEXP_TARGET_NODE]
    23  	if !targetNodeFound {
    24  		panic("[create mapping] ERROR: target node not found.")
    25  	}
    26  
    27  	newMapping := Mapping{
    28  		synch:        synch,
    29  		source:       synch.dbStore.nodes[mapping[cfg.PSUBEXP_SOURCE_NODE]],
    30  		target:       synch.dbStore.nodes[mapping[cfg.PSUBEXP_TARGET_NODE]],
    31  		sourceColumn: mapping[cfg.PSUBEXP_SOURCE_COLUMN],
    32  		targetColumn: mapping[cfg.PSUBEXP_TARGET_COLUMN],
    33  		raw:          mapping,
    34  	}
    35  
    36  	return &newMapping
    37  }