Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuah committed Jul 6, 2015
1 parent 762524a commit 6eda0cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -92,15 +92,15 @@ type Follow struct {
FollowUserId int64
}


//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(func(tx gomodel.Tx, f *Follow) error {
stmt, err := tx.PrepareById(insertUserFollowSQL)
c, err := gomodel.CloseUpdate(stmt, err, gomodel.FieldVals(f, followFieldsAll, f.FollowUserId)...)
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)
Expand All @@ -110,7 +110,7 @@ func (f *Follow) Add() error {
}

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

Expand All @@ -127,6 +127,7 @@ func (f *Follow) updateFollowInfo(tx gomodel.Tx, err error, c int) error {
}
return err
}

```

# LICENSE
Expand Down
3 changes: 1 addition & 2 deletions example/userfollow/follow.go
Expand Up @@ -23,8 +23,7 @@ type Follow struct {
//]
func (f *Follow) Add() error {
return f.txDo(DB, func(tx gomodel.Tx, f *Follow) error {
stmt, err := tx.PrepareById(insertUserFollowSQL)
c, err := gomodel.CloseUpdate(stmt, err, gomodel.FieldVals(f, followFieldsAll, f.FollowUserId)...)
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)
Expand Down

0 comments on commit 6eda0cf

Please sign in to comment.