(csvRelPath string, dst schema.Tabler, nullable bool)
| 151 | } |
| 152 | |
| 153 | func (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. |
| 183 | func (t *DataFlowTester) ImportCsvIntoTabler(csvRelPath string, dst schema.Tabler) { |
no test coverage detected