I'm trying to load about 20k items in a sqlite3 database using a little Golang program.
But, it takes a lot of time... Like 45mins...
I've try doing :
_,errExec:=db.Exec("Insert into ...")
Is there any solution the reduce the update or insert (of about 20k items) in under 5mins ? and if yes, how can I do ?
Thank you for your answer.
EDIT : The full function :
func updateDB(){
file, err := ioutil.ReadFile("./database/id.json")
if err != nil {
fmt.Printf("File error: %v\n", err)
os.Exit(1)
}
var ids []int
json.Unmarshal(file, &ids)
db, err := sql.Open("sqlite3","./database/gwitem.db")
if err != nil {
log.Fatal(err.Error())
}
defer db.Close()
var prix price
for i :=0; i < len(ids); i++{
//getJson("https://api.guildwars2.com/v2/commerce/prices/"+strconv.Itoa(ids[i]),&prix)
url := "https://api.guildwars2.com/v2/commerce/prices/"+strconv.Itoa(ids[i])
getJson(url,&prix)
_,errExec:=db.Exec("Insert into trade values(null,"+strconv.FormatInt(prix.Id,10)+","+strconv.FormatInt(prix.Buys.Quantity,10)+","+strconv.FormatInt(prix.Buys.Unit_price,10)+","+strconv.FormatInt(prix.Sells.Quantity,10)+","+strconv.FormatInt(prix.Sells.Unit_price,10)+",0)")
if errExec != nil{
fmt.Println(err.Error())
log.Fatal(err)
}
}
}