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

Commit

Permalink
update template file, fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuah committed Apr 7, 2016
1 parent 65931a8 commit de9d382
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
gomodel.iml
vendor
12 changes: 6 additions & 6 deletions cmd/gomodel/model.tmpl
Expand Up @@ -24,7 +24,7 @@ const (
)

var (
{{$unexport}}Instance = new({{$normal}})
{{$normal}}Instance = new({{$normal}})
)

func {{$recv}} Table() string {
Expand Down Expand Up @@ -73,7 +73,7 @@ func {{$recv}} Ptrs(fields uint64, ptrs []interface{}) {
}
}

func {{$recv}} txDo(db *gomodel.DB, do func(*gomodel.Tx, *{{$normal}}) error) error {
func {{$recv}} txDo(exec gomodel.Executor, do func(*gomodel.Tx, *{{$normal}}) error) error {
var (
tx *gomodel.Tx
err error
Expand All @@ -83,10 +83,10 @@ func {{$recv}} txDo(db *gomodel.DB, do func(*gomodel.Tx, *{{$normal}}) error) er
tx = r
case *gomodel.DB:
tx, err = r.Begin()
if err != nil {
return err
}
defer tx.Close()
if err != nil {
return err
}
defer tx.Close()
default:
panic("unexpected underlay type of gomodel.Executor")
}
Expand Down
4 changes: 2 additions & 2 deletions example/userfollow/follow.go
Expand Up @@ -43,9 +43,9 @@ func (f *Follow) Delete() error {

func (f *Follow) updateFollowInfo(tx *gomodel.Tx, err error, c int) error {
if err == nil {
_, err = tx.ArgsIncrBy(userInstance, USER_FOLLOWINGS, USER_ID, c, f.UserId)
_, err = tx.ArgsIncrBy(UserInstance, USER_FOLLOWINGS, USER_ID, c, f.UserId)
if err == nil {
_, err = tx.ArgsIncrBy(userInstance, USER_FOLLOWERS, USER_ID, c, f.FollowUserId)
_, err = tx.ArgsIncrBy(UserInstance, USER_FOLLOWERS, USER_ID, c, f.FollowUserId)
}
}
return err
Expand Down
8 changes: 4 additions & 4 deletions example/userfollow/model_gen.go
Expand Up @@ -28,7 +28,7 @@ const (
)

var (
userInstance = new(User)
UserInstance = new(User)
)

func (u *User) Table() string {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (u *User) Ptrs(fields uint64, ptrs []interface{}) {
}
}

func (u *User) txDo(db *gomodel.DB, do func(*gomodel.Tx, *User) error) error {
func (u *User) txDo(exec gomodel.Executor, do func(*gomodel.Tx, *User) error) error {
var (
tx *gomodel.Tx
err error
Expand Down Expand Up @@ -193,7 +193,7 @@ const (
)

var (
followInstance = new(Follow)
FollowInstance = new(Follow)
)

func (f *Follow) Table() string {
Expand Down Expand Up @@ -246,7 +246,7 @@ func (f *Follow) Ptrs(fields uint64, ptrs []interface{}) {
}
}

func (f *Follow) txDo(db *gomodel.DB, do func(*gomodel.Tx, *Follow) error) error {
func (f *Follow) txDo(exec gomodel.Executor, do func(*gomodel.Tx, *Follow) error) error {
var (
tx *gomodel.Tx
err error
Expand Down
6 changes: 3 additions & 3 deletions example/userfollow/user.go
Expand Up @@ -34,7 +34,7 @@ func (u *User) Add() error {
}

func DeleteUserById(id int64) error {
c, err := DB.ArgsDelete(userInstance, USER_ID, id)
c, err := DB.ArgsDelete(UserInstance, USER_ID, id)

return dberrs.NoAffects(c, err, ErrNoUser)
}
Expand All @@ -56,7 +56,7 @@ func UsersByAge(age, start, count int) ([]User, error) {
Fields: userFieldsAll,
}

err := DB.ArgsLimit(&users, userInstance, userFieldsAll, USER_AGE, age, start, count)
err := DB.ArgsLimit(&users, UserInstance, userFieldsAll, USER_AGE, age, start, count)
return users.Values, dberrs.NoRows(err, ErrNoUser)
}

Expand All @@ -65,6 +65,6 @@ func AllUsersByAge(age int) ([]User, error) {
Fields: userFieldsAll,
}

err := DB.ArgsAll(&users, userInstance, userFieldsAll, USER_AGE, age)
err := DB.ArgsAll(&users, UserInstance, userFieldsAll, USER_AGE, age)
return users.Values, dberrs.NoRows(err, ErrNoUser)
}

0 comments on commit de9d382

Please sign in to comment.