Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions example/model/gen.object.user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ func (m *_UserRedisMgr) Fetch(pk PrimaryKey) (*User, error) {
func (m *_UserRedisMgr) FetchByKey(key string) (*User, error) {
obj := UserMgr.NewUser()

ctx := context.Background()
ctx := context.TODO()
pipe := m.BeginPipeline()
pipe.Exists(ctx, key)
pipe.HMGet(ctx, key,
Expand Down Expand Up @@ -1914,10 +1914,14 @@ func (m *_UserRedisMgr) FetchByKey(key string) (*User, error) {
}

func (m *_UserRedisMgr) FetchByPrimaryKeys(pks []PrimaryKey) ([]*User, error) {
if len(pks) == 0 {
return nil, orm.ErrPrimaryKeysIsEmpty
}

objs := make([]*User, 0, len(pks))
pipe := m.BeginPipeline()
obj := UserMgr.NewUser()
ctx := context.Background()
ctx := context.TODO()
for _, pk := range pks {
key := pk.Key()
pipe.Exists(ctx, keyOfObject(obj, key))
Expand Down Expand Up @@ -2217,7 +2221,7 @@ func (m *_UserRedisMgr) Delete(obj *User) error {
return err
}

ctx := context.Background()
ctx := context.TODO()
if err := pipe.Del(ctx, keyOfObject(obj, pk.Key())).Err(); err != nil {
return err
}
Expand Down Expand Up @@ -2262,7 +2266,7 @@ func (m *_UserRedisMgr) SaveWithExpire(obj *User, expire time.Duration) error {
pipe.Close()
return err
}
if _, err = pipe.Exec(context.Background()); err != nil {
if _, err = pipe.Exec(context.TODO()); err != nil {
pipe.Close()
return err
}
Expand All @@ -2271,7 +2275,7 @@ func (m *_UserRedisMgr) SaveWithExpire(obj *User, expire time.Duration) error {
}

func (m *_UserRedisMgr) addToPipeline(pipe *_UserRedisPipeline, obj *User, expire time.Duration) error {
ctx := context.Background()
ctx := context.TODO()
pk := obj.GetPrimaryKey()
key := pk.Key()
//! fields
Expand Down
5 changes: 5 additions & 0 deletions orm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package orm

import (
"database/sql"
"errors"
"strings"
)

Expand All @@ -10,3 +11,7 @@ import (
func IsErrNotFound(err error) bool {
return strings.Contains(err.Error(), "not found") || err == sql.ErrNoRows
}

var (
ErrPrimaryKeysIsEmpty = errors.New("redis-orm: provided primary keys are empty")
)
6 changes: 3 additions & 3 deletions tpl/bindata.go

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions tpl/object.redis.read.gogo
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (m *_{{$obj.Name}}RedisMgr) Fetch(pk PrimaryKey) (*{{$obj.Name}}, error) {
func (m *_{{$obj.Name}}RedisMgr) FetchByKey(key string) (*{{$obj.Name}}, error) {
obj := {{$obj.Name}}Mgr.New{{$obj.Name}}()

ctx := context.Background()
ctx := context.TODO()
pipe := m.BeginPipeline()
pipe.Exists(ctx, key)
pipe.HMGet(ctx, key,
Expand Down Expand Up @@ -214,10 +214,14 @@ func (m *_{{$obj.Name}}RedisMgr) FetchByKey(key string) (*{{$obj.Name}}, error)
}

func (m *_{{$obj.Name}}RedisMgr) FetchByPrimaryKeys(pks []PrimaryKey) ([]*{{$obj.Name}}, error) {
if len(pks) == 0 {
return nil, orm.ErrPrimaryKeysIsEmpty
}

objs := make([]*{{$obj.Name}}, 0, len(pks))
pipe := m.BeginPipeline()
obj := {{$obj.Name}}Mgr.New{{$obj.Name}}()
ctx := context.Background()
ctx := context.TODO()
for _, pk := range pks {
key := pk.Key()
pipe.Exists(ctx, keyOfObject(obj, key))
Expand Down
6 changes: 3 additions & 3 deletions tpl/object.redis.write.gogo
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m *_{{$obj.Name}}RedisMgr) Delete(obj *{{$obj.Name}}) error {
}
{{- end}}

ctx := context.Background()
ctx := context.TODO()
if err := pipe.Del(ctx, keyOfObject(obj, pk.Key())).Err(); err != nil {
return err
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func (m *_{{$obj.Name}}RedisMgr) SaveWithExpire(obj *{{$obj.Name}}, expire time.
pipe.Close()
return err
}
if _, err = pipe.Exec(context.Background()); err != nil {
if _, err = pipe.Exec(context.TODO()); err != nil {
pipe.Close()
return err
}
Expand All @@ -148,7 +148,7 @@ func (m *_{{$obj.Name}}RedisMgr) SaveWithExpire(obj *{{$obj.Name}}, expire time.
}

func (m *_{{$obj.Name}}RedisMgr) addToPipeline(pipe * _{{$obj.Name}}RedisPipeline, obj *{{$obj.Name}}, expire time.Duration) error {
ctx := context.Background()
ctx := context.TODO()
pk := obj.GetPrimaryKey()
key := pk.Key()
//! fields
Expand Down
8 changes: 2 additions & 6 deletions tpl/relation.pair.sync.gogo
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ func (m *_{{$relation.Name}}RedisMgr) AddBySQL(db DBFetcher, sql string, args ..
if err != nil {
return err
}

ctx := context.TODO()
for _, obj := range objs {
if err := m.PairAdd(ctx, obj.(*{{$relation.Name}})); err != nil {
if err := m.PairAdd(obj.(*{{$relation.Name}})); err != nil {
return err
}
}
Expand All @@ -34,10 +32,8 @@ func (m *_{{$relation.Name}}RedisMgr) DelBySQL(db DBFetcher, sql string, args ..
if err != nil {
return err
}

ctx := context.TODO()
for _, obj := range objs {
if err := m.PairRem(ctx, fmt.Sprint(obj.(*{{$relation.Name}}).{{$primaryField.Name}})); err != nil {
if err := m.PairRem(fmt.Sprint(obj.(*{{$relation.Name}}).{{$primaryField.Name}})); err != nil {
return err
}
}
Expand Down