Exemple #1
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.DuplicateKeyError(err, dberrs.PRIMARY_KEY, ErrFollowed)

		return f.updateFollowInfo(tx, err, 1)
	})
}
Exemple #2
0
func (u *User) Add() error {
	u.Followings = 0
	u.Followers = 0

	id, err := DB.Insert(u, userFieldsExcpId, gomodel.RES_ID)
	err = dberrs.DuplicateKeyError(DB, err, UserNameCol, ErrDuplicateUserName)
	if err == nil {
		u.Id = id
	}

	return err
}