示例#1
0
func (f *Follow) Delete() error {
	return f.txDo(DB, func(tx *gomodel.Tx, f *Follow) error {
		c, err := tx.Delete(f, followFieldsAll)
		err = dberrs.NoAffects(c, err, ErrNonFollow)

		return f.updateFollowInfo(tx, err, -1)
	})
}
示例#2
0
//gomodel insertUserFollowSQL = [
//  INSERT INTO Follow(UserId, FollowUserId)
//      SELECT ?, ? FROM DUAL
//      WHERE EXISTS(SELECT Id FROM User WHERE Id=?)
//]
func (f *Follow) Add() error {
	return f.txDo(DB, func(tx *gomodel.Tx, f *Follow) error {
		c, err := tx.UpdateById(insertUserFollowSQL, gomodel.FieldVals(f, followFieldsAll, f.FollowUserId)...)

		err = dberrs.NoAffects(c, err, ErrNoUser)
		err = dberrs.DuplicatePrimaryKeyError(tx, err, ErrFollowed)

		return f.updateFollowInfo(tx, err, 1)
	})
}
示例#3
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)
	}
}
示例#4
0
func (u *User) Update() error {
	c, err := DB.Update(u, USER_NAME|USER_AGE, USER_ID)

	return dberrs.NoAffects(c, err, ErrNoUser)
}
示例#5
0
func DeleteUserById(id int64) error {
	c, err := DB.ArgsDelete(userInstance, USER_ID, id)

	return dberrs.NoAffects(c, err, ErrNoUser)
}
示例#6
0
文件: rdb.go 项目: cosiner/gotmsq
//gomodel deleteMessageByIdSQL = [
//  DELETE FROM message WHERE Id=?
//]
func (d *DB) Delete(id string) error {
	c, err := gomodel.Update(d.stmtDeleteById, nil, id)

	return dberrs.NoAffects(c, err, gotmsq.ErrNoMessage)
}
示例#7
0
文件: rdb.go 项目: cosiner/gotmsq
//gomodel deleteTimeoutMessagesSQL = [
//  DELETE FROM message WHERE Timing < ?
//]
func (d *DB) DeleteTimeouts() error {
	t := d.timingString(0)
	c, err := gomodel.Exec(d.stmtClearTimeout, nil, gomodel.RES_NO, t)

	return dberrs.NoAffects(c, err, gotmsq.ErrNoMessage)
}