File tree Expand file tree Collapse file tree 1 file changed +0
-40
lines changed Expand file tree Collapse file tree 1 file changed +0
-40
lines changed Original file line number Diff line number Diff line change 44
55package models
66
7- import "xorm.io/builder"
8-
97// DBContext represents a db context
108type 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
5313func WithContext (f func (ctx DBContext ) error ) error {
5414 return f (DBContext {x })
You can’t perform that action at this time.
0 commit comments