func (c *CRUD) Update(id interface{}, v map[string]interface{}) error { keys, vals := readUpdateKey(v) vals = append(vals, id) queryString := fmt.Sprintf("UPDATE %s SET %s WHERE id=?", c.tableName, keys) result, err := c.db.Exec(queryString, vals...) if i, _ := result.RowsAffected(); i == 0 { return errs.NewNotFound("not found") } return errs.Sql(err) }
func TestDelete(t *testing.T) { crud := getSetup() now := time.Now() v := testData{ID: 12, Name: "Xier", Time: now, Height: 1500, Weight: 25.55} err := crud.Create(&v) assert.NoError(t, err) err = crud.Delete(v.ID) assert.NoError(t, err) var tempData testData err = crud.db.Get(&tempData, "SELECT * FROM testTable WHERE id=12") err = errs.Sql(err) assert.Error(t, err) assert.True(t, errs.IsNotFound(err)) }