Answers for "gorm mysql unique constraint show errors example"

Go
1

gorm mysql unique constraint show errors example

type GormErr struct {
  Number  int    `json:"Number"`
  Message string `json:"Message"`
}

err, _ = DoFuncOnDB(); // funtion to do some ops on DB

byteErr, _ := json.Marshal(err)
var newError types.GormErr
json.Unmarshal((byteErr), &newError)

switch newError.Number {
	case 1062: fmt.Println("Duplicate key Error")
}
Posted by: Guest on July-21-2021

Code answers related to "gorm mysql unique constraint show errors example"

Browse Popular Code Answers by Language