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)
| 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 |
| 136 | func (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. |
no test coverage detected