github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/others/func/import/city.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/easysoft/zendata/cmd/test/others/func/comm" 7 "github.com/easysoft/zendata/cmd/test/others/func/model" 8 ) 9 10 func main() { 11 filePath := "data/city/cn.v1.xlsx" 12 sheetName := "city" 13 14 db := comm.GetDB() 15 db.Exec(fmt.Sprintf(comm.TruncateTable, model.DataCity{}.TableName())) 16 db.AutoMigrate( 17 &model.DataCity{}, 18 ) 19 20 records := comm.GetExcelTable(filePath, sheetName) 21 22 for _, record := range records { 23 po := model.DataCity{ 24 Name: record["city"].(string), 25 Code: record["cityCode"].(string), 26 ZipCode: record["zipCode"].(string), 27 State: record["state"].(string), 28 StateShort: record["stateShort"].(string), 29 StateShort2: record["stateShort2"].(string), 30 } 31 32 db.Save(&po) 33 } 34 }