forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
89 lines (76 loc) · 2.48 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gen
import (
"database/sql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"gorm.io/gen/field"
)
type (
// Condition query condition
// field.Expr and subquery are expect value
Condition interface {
BeCond() interface{}
CondError() error
}
)
var (
_ Condition = (field.Expr)(nil)
_ Condition = (field.Value)(nil)
_ Condition = (subQuery)(nil)
_ Condition = (Dao)(nil)
)
type subQuery interface {
underlyingDB() *gorm.DB
underlyingDO() *DO
Condition
}
// TODO implement Associations api (ex: preload)
// Dao CRUD methods
type Dao interface {
subQuery
As(alias string) Dao
Not(conds ...Condition) Dao
Or(conds ...Condition) Dao
Select(columns ...field.Expr) Dao
Where(conds ...Condition) Dao
Order(columns ...field.Expr) Dao
Distinct(columns ...field.Expr) Dao
Omit(columns ...field.Expr) Dao
Joins(tableName string, args ...field.Expr) Dao
Join(table schema.Tabler, conds ...field.Expr) Dao
LeftJoin(table schema.Tabler, conds ...field.Expr) Dao
RightJoin(table schema.Tabler, conds ...field.Expr) Dao
Group(columns field.Expr) Dao
Having(conds ...Condition) Dao
Limit(limit int) Dao
Offset(offset int) Dao
Scopes(funcs ...func(Dao) Dao) Dao
Unscoped() Dao
Attrs(attrs ...field.Expr) Dao
Assign(attrs ...field.Expr) Dao
Preload(tableName string, args ...field.Expr) Dao
Create(value interface{}) error
CreateInBatches(value interface{}, batchSize int) error
Save(value interface{}) error
First() (result interface{}, err error)
Take() (result interface{}, err error)
Last() (result interface{}, err error)
Find() (results interface{}, err error)
FindInBatch(batchSize int, fc func(tx Dao, batch int) error) (results interface{}, err error)
FindInBatches(dest interface{}, batchSize int, fc func(tx Dao, batch int) error) error
FirstOrInit() (result interface{}, err error)
FirstOrCreate() (result interface{}, err error)
Update(column field.Expr, value interface{}) (info resultInfo, err error)
UpdateSimple(columns ...field.Expr) (info resultInfo, err error)
Updates(values interface{}) (info resultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info resultInfo, err error)
UpdateColumns(values interface{}) (info resultInfo, err error)
UpdateColumnSimple(columns ...field.Expr) (info resultInfo, err error)
Delete() (info resultInfo, err error)
Count() (int64, error)
Row() *sql.Row
Rows() (*sql.Rows, error)
Scan(dest interface{}) error
Pluck(column field.Expr, dest interface{}) error
ScanRows(rows *sql.Rows, dest interface{}) error
}