File tree 1 file changed +0
-40
lines changed
1 file changed +0
-40
lines changed Original file line number Diff line number Diff line change 4
4
5
5
package models
6
6
7
- import "xorm.io/builder"
8
-
9
7
// DBContext represents a db context
10
8
type DBContext struct {
11
9
e Engine
12
10
}
13
11
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
-
52
12
// WithContext represents executing database operations
53
13
func WithContext (f func (ctx DBContext ) error ) error {
54
14
return f (DBContext {x })
You can’t perform that action at this time.
0 commit comments