MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / dumpTableConstraints

Method dumpTableConstraints

dgraph/cmd/migrate/dump.go:136–167  ·  view source on GitHub ↗

dumpTableConstraints reads data from a table, and then generate RDF entries from a row to another row in a foreign table by following columns with foreign key constraints. It then sends the generated RDF entries to the m.dataWriter

(table string)

Source from the content-addressed store, hash-verified

134// from a row to another row in a foreign table by following columns with foreign key constraints.
135// It then sends the generated RDF entries to the m.dataWriter
136func (m *dumpMeta) dumpTableConstraints(table string) error {
137 tableGuide := m.tableGuides[table]
138 tableInfo := m.tableInfos[table]
139
140 escapedColNames := escapeColumnNames(tableInfo.columnNames)
141
142 query := fmt.Sprintf(`select %s from %s`, strings.Join(escapedColNames, ","), table)
143 rows, err := m.sqlPool.Query(query)
144 if err != nil {
145 return err
146 }
147 defer rows.Close()
148
149 row := &sqlRow{
150 tableInfo: tableInfo,
151 }
152 for rows.Next() {
153 // step 1: read the row's column values
154 colValues, err := getColumnValues(tableInfo.columnNames, tableInfo.columnDataTypes, rows)
155 if err != nil {
156 return err
157 }
158 row.values = colValues
159
160 // step 2: output the constraints in RDF format
161 row.blankNodeLabel = tableGuide.blankNode.generate(tableInfo, colValues)
162
163 m.outputConstraints(row, tableInfo)
164 }
165
166 return nil
167}
168
169// outputRow takes a row with its metadata as well as the table metadata, and
170// spits out one or more RDF entries to the dumpMeta's dataWriter.

Callers 1

dumpTablesMethod · 0.95

Calls 7

outputConstraintsMethod · 0.95
escapeColumnNamesFunction · 0.85
getColumnValuesFunction · 0.85
CloseMethod · 0.65
generateMethod · 0.65
QueryMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected