MCPcopy
hub / github.com/dgraph-io/dgraph / generate

Method generate

dgraph/cmd/migrate/table_guide.go:35–55  ·  view source on GitHub ↗

As an example, if the employee table has 3 columns (f_name, l_name, and title), where f_name and l_name together form the primary key. Then a row with values John (f_name), Doe (l_name), Software Engineer (title) would generate a blank node label _:person_John_Doe using values from the primary key c

(info *sqlTable, values []interface{})

Source from the content-addressed store, hash-verified

33// would generate a blank node label _:person_John_Doe using values from the primary key columns
34// in the alphabetic order, that is f_name, l_name in this case.
35func (g *usingColumns) generate(info *sqlTable, values []interface{}) string {
36 if g.primaryKeyIndices == nil {
37 g.primaryKeyIndices = getColumnIndices(info, func(info *sqlTable, column string) bool {
38 return info.columns[column].keyType == primary
39 })
40 }
41
42 // use the primary key indices to retrieve values in the current row
43 var parts []string
44 parts = append(parts, info.tableName)
45 for _, columnIndex := range g.primaryKeyIndices {
46 strVal, err := getValue(info.columns[columnIndex.name].dataType,
47 values[columnIndex.index])
48 if err != nil {
49 logger.Fatalf("Unable to get string value from primary key column %s", columnIndex.name)
50 }
51 parts = append(parts, strVal)
52 }
53
54 return fmt.Sprintf("_:%s", strings.Join(parts, separator))
55}
56
57// A usingCounter generates blank node labels using a row counter
58type usingCounter struct {

Callers

nothing calls this directly

Calls 3

getColumnIndicesFunction · 0.85
FatalfMethod · 0.80
getValueFunction · 0.70

Tested by

no test coverage detected