Example #1
0
func CheckFieldForIncrBy(field, fields uint64, count int64) {
	if gomodel.NumFields(field) == 0 || field&fields == 0 {
		panic(errors.Newf("unexpected field type %d", field))
	}

	if count != -1 && count != 1 {
		panic(errors.Newf("unexpected field incrby count %d, must be -1 or 1", count))
	}
}
Example #2
0
func FuncForIncrByFieldCount(defaultRunner gomodel.Executor, model gomodel.Model, fields, whereFields uint64, noAffectsError error) IncrByFunc {
	if gomodel.NumFields(whereFields) == 0 || gomodel.NumFields(fields) == 0 {
		panic(errors.Newf("unexpected field count of fields %d and whereField %d", fields, whereFields))
	}

	return func(exec gomodel.Executor, field uint64, whereArgs ...interface{}) error {
		var count int64
		switch arg := whereArgs[0].(type) {
		case int:
			count = int64(arg)
		case int8:
			count = int64(arg)
		case int16:
			count = int64(arg)
		case int32:
			count = int64(arg)
		case int64:
			count = int64(arg)
		case uint8:
			count = int64(arg)
		case uint16:
			count = int64(arg)
		case uint32:
			count = int64(arg)
		case uint64:
			count = int64(arg)
		default:
			panic(fmt.Sprintf("count %v must be an integer", arg))
		}
		CheckFieldForIncrBy(field, fields, count)
		if exec == nil {
			exec = defaultRunner
		}
		c, err := exec.ArgsIncrBy(model, field, whereFields, whereArgs...)
		return dberrs.NoAffects(c, err, noAffectsError)
	}
}