fix: add role limit
This commit is contained in:
@@ -93,6 +93,24 @@ func Upsert[T any](colMap map[string]interface{}) (ok bool, rowsAffected int64)
|
||||
return true, tx.RowsAffected
|
||||
}
|
||||
|
||||
func Update[T any](queryMap []map[string]interface{}, updateMap map[string]interface{}) (ok bool, rowsAffected int64) {
|
||||
tx := global.Db.Model(new(T))
|
||||
for _, e := range queryMap {
|
||||
e[IS_DELETE] = 0
|
||||
tx = tx.Or(e)
|
||||
}
|
||||
return UpdateByOrm(tx, updateMap)
|
||||
}
|
||||
|
||||
func UpdateByOrm(tx *gorm.DB, updateMap map[string]interface{}) (ok bool, rowsAffected int64) {
|
||||
tx.Updates(updateMap)
|
||||
if tx.Error != nil {
|
||||
fmt.Println(tx.Error)
|
||||
return false, 0
|
||||
}
|
||||
return true, tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteById will delete by id, not delete the record from database, only set the field "is_delete" as 1
|
||||
func DeleteById[T any](id int) (ok bool, rowsAffected int64) {
|
||||
tx := global.Db.Model(new(T)).Where("id = ?", id).Update("is_delete", 1)
|
||||
|
||||
Reference in New Issue
Block a user