Skip to content

Commit 46e236f

Browse files
committed
don't expose db functions
1 parent 1dcd33c commit 46e236f

File tree

1 file changed

+0
-40
lines changed

1 file changed

+0
-40
lines changed

models/context.go

-40
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,11 @@
44

55
package models
66

7-
import "xorm.io/builder"
8-
97
// DBContext represents a db context
108
type DBContext struct {
119
e Engine
1210
}
1311

14-
// Insert inserts a object to database
15-
func (ctx *DBContext) Insert(obj interface{}) error {
16-
_, err := ctx.e.Insert(obj)
17-
return err
18-
}
19-
20-
// LoadByID loads record from database according id, if it's not exist return ErrNotExist
21-
func (ctx *DBContext) LoadByID(id int64, obj interface{}) error {
22-
has, err := ctx.e.ID(id).Get(obj)
23-
if err != nil {
24-
return err
25-
} else if !has {
26-
return ErrNotExist{ID: id}
27-
}
28-
return nil
29-
}
30-
31-
// FindByConditions loads records by conditions
32-
func (ctx *DBContext) FindByConditions(conds builder.Cond, objs interface{}) error {
33-
return ctx.e.Where(conds).Find(objs)
34-
}
35-
36-
// DeleteByID deletes a object by id
37-
func (ctx *DBContext) DeleteByID(id int64, obj interface{}) error {
38-
_, err := ctx.e.ID(id).NoAutoCondition().Delete(obj)
39-
return err
40-
}
41-
42-
// UpdateByID updates a record
43-
func (ctx *DBContext) UpdateByID(id int64, obj interface{}, cols ...string) error {
44-
sess := ctx.e.ID(id)
45-
if len(cols) > 0 {
46-
sess.Cols(cols...)
47-
}
48-
_, err := sess.Update(obj)
49-
return err
50-
}
51-
5212
// WithContext represents executing database operations
5313
func WithContext(f func(ctx DBContext) error) error {
5414
return f(DBContext{x})

0 commit comments

Comments
 (0)