Using transaction instead of normal handle to do multiple queries
parent
64bbaed3ed
commit
81592af770
|
@ -166,6 +166,11 @@ func RetrieveAccountEggs(uuid []byte) ([]defs.EggData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAccountEggs(uuid []byte, eggs []defs.EggData) error {
|
func UpdateAccountEggs(uuid []byte, eggs []defs.EggData) error {
|
||||||
|
tx, err := handle.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, egg := range eggs {
|
for _, egg := range eggs {
|
||||||
// TODO: find a fix to enforce encoding from body to EggData only if
|
// TODO: find a fix to enforce encoding from body to EggData only if
|
||||||
// it respects the EggData struct so we can get rid of the test
|
// it respects the EggData struct so we can get rid of the test
|
||||||
|
@ -173,7 +178,7 @@ func UpdateAccountEggs(uuid []byte, eggs []defs.EggData) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = handle.Exec(`INSERT INTO eggs (uuid, owner, gachaType, hatchWaves, timestamp)
|
_, err = tx.Exec(`INSERT INTO eggs (uuid, owner, gachaType, hatchWaves, timestamp)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
ON DUPLICATE KEY UPDATE hatchWaves = ?`,
|
ON DUPLICATE KEY UPDATE hatchWaves = ?`,
|
||||||
egg.Id, uuid, egg.GachaType, egg.HatchWaves, egg.Timestamp, egg.HatchWaves)
|
egg.Id, uuid, egg.GachaType, egg.HatchWaves, egg.Timestamp, egg.HatchWaves)
|
||||||
|
@ -182,6 +187,11 @@ func UpdateAccountEggs(uuid []byte, eggs []defs.EggData) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue