Skip to content

Update方法

Tuuz edited this page Jun 20, 2022 · 3 revisions

普通update方法

func Api_update_img(id, img interface{}) bool {
	db := tuuz.Db().Table(Table)
	where := map[string]interface{}{
		"id": id,
	}
	db.Where(where)
	data := map[string]interface{}{
		"img": img,
	}
	db.Data(data)
	_, err := db.Update()
	if err != nil {
		Log.Dbrr(err, tuuz.FUNCTION_ALL())
		return false
	} else {
		return true
	}
}

事务update方法

func (self *Interface) Api_update_img(id, parent_id, img interface{}) bool {
	db := self.Db.Table(Table)
	where := map[string]interface{}{
		"id":        id,
		"parent_id": parent_id,
	}
	db.Where(where)
	data := map[string]interface{}{
		"img": img,
	}
	db.Data(data)
	_, err := db.Update()
	if err != nil {
		Log.Dbrr(err, tuuz.FUNCTION_ALL())
		return false
	} else {
		return true
	}
}