MCPcopy
hub / github.com/apache/devlake / importCsv

Method importCsv

backend/helpers/e2ehelper/data_flow_tester.go:153–180  ·  view source on GitHub ↗
(csvRelPath string, dst schema.Tabler, nullable bool)

Source from the content-addressed store, hash-verified

151}
152
153func (t *DataFlowTester) importCsv(csvRelPath string, dst schema.Tabler, nullable bool) {
154 csvIter, err := pluginhelper.NewCsvFileIterator(csvRelPath)
155 if err != nil {
156 panic(err)
157 }
158 defer csvIter.Close()
159 t.FlushTabler(dst)
160 // load rows and insert into target table
161 for csvIter.HasNext() {
162 toInsertValues := csvIter.Fetch()
163 for i := range toInsertValues {
164 if nullable {
165 if toInsertValues[i].(string) == `NULL` {
166 toInsertValues[i] = nil
167 }
168 } else {
169 if toInsertValues[i].(string) == `` {
170 toInsertValues[i] = nil
171 }
172 }
173 }
174 result := t.Db.Model(dst).Create(toInsertValues)
175 if result.Error != nil {
176 panic(result.Error)
177 }
178 assert.Equal(t.T, int64(1), result.RowsAffected)
179 }
180}
181
182// ImportCsvIntoTabler imports records from specified csv file into target tabler, the empty string will be taken as NULL. note that existing data would be deleted first.
183func (t *DataFlowTester) ImportCsvIntoTabler(csvRelPath string, dst schema.Tabler) {

Callers 2

ImportCsvIntoTablerMethod · 0.95

Calls 5

CloseMethod · 0.95
FlushTablerMethod · 0.95
HasNextMethod · 0.95
FetchMethod · 0.95
CreateMethod · 0.65

Tested by

no test coverage detected