types.go 4.7 KB
Newer Older
S
slene 已提交
1 2 3 4 5
package orm

import (
	"database/sql"
	"reflect"
6
	"time"
S
slene 已提交
7 8
)

F
FuXiaoHei 已提交
9
// database driver
S
slene 已提交
10 11 12 13 14
type Driver interface {
	Name() string
	Type() DriverType
}

F
FuXiaoHei 已提交
15
// field info
S
slene 已提交
16 17 18 19 20 21 22
type Fielder interface {
	String() string
	FieldType() int
	SetRaw(interface{}) error
	RawValue() interface{}
}

F
FuXiaoHei 已提交
23
// orm struct
S
slene 已提交
24
type Ormer interface {
25
	Read(interface{}, ...string) error
K
Kyle McCullough 已提交
26
	ReadOrCreate(interface{}, string, ...string) (bool, int64, error)
27
	Insert(interface{}) (int64, error)
S
slene 已提交
28
	InsertMulti(int, interface{}) (int64, error)
29
	Update(interface{}, ...string) (int64, error)
30
	Delete(interface{}) (int64, error)
31 32
	LoadRelated(interface{}, string, ...interface{}) (int64, error)
	QueryM2M(interface{}, string) QueryM2Mer
S
slene 已提交
33 34 35 36 37 38
	QueryTable(interface{}) QuerySeter
	Using(string) error
	Begin() error
	Commit() error
	Rollback() error
	Raw(string, ...interface{}) RawSeter
S
slene 已提交
39
	Driver() Driver
S
slene 已提交
40 41
}

F
FuXiaoHei 已提交
42
// insert prepared statement
S
slene 已提交
43
type Inserter interface {
44
	Insert(interface{}) (int64, error)
S
slene 已提交
45 46 47
	Close() error
}

F
FuXiaoHei 已提交
48
// query seter
S
slene 已提交
49 50 51
type QuerySeter interface {
	Filter(string, ...interface{}) QuerySeter
	Exclude(string, ...interface{}) QuerySeter
S
slene 已提交
52
	SetCond(*Condition) QuerySeter
53
	Limit(interface{}, ...interface{}) QuerySeter
54
	Offset(interface{}) QuerySeter
S
slene 已提交
55 56 57
	OrderBy(...string) QuerySeter
	RelatedSel(...interface{}) QuerySeter
	Count() (int64, error)
S
slene 已提交
58
	Exist() bool
S
slene 已提交
59 60 61
	Update(Params) (int64, error)
	Delete() (int64, error)
	PrepareInsert() (Inserter, error)
62 63
	All(interface{}, ...string) (int64, error)
	One(interface{}, ...string) error
S
slene 已提交
64 65 66 67 68
	Values(*[]Params, ...string) (int64, error)
	ValuesList(*[]ParamsList, ...string) (int64, error)
	ValuesFlat(*ParamsList, string) (int64, error)
}

F
FuXiaoHei 已提交
69
// model to model query struct
70 71 72 73 74 75 76 77
type QueryM2Mer interface {
	Add(...interface{}) (int64, error)
	Remove(...interface{}) (int64, error)
	Exist(interface{}) bool
	Clear() (int64, error)
	Count() (int64, error)
}

F
FuXiaoHei 已提交
78
// raw query statement
S
slene 已提交
79
type RawPreparer interface {
80
	Exec(...interface{}) (sql.Result, error)
S
slene 已提交
81 82 83
	Close() error
}

F
FuXiaoHei 已提交
84
// raw query seter
S
slene 已提交
85
type RawSeter interface {
86
	Exec() (sql.Result, error)
S
slene 已提交
87 88 89
	QueryRow(...interface{}) error
	QueryRows(...interface{}) (int64, error)
	SetArgs(...interface{}) RawSeter
S
slene 已提交
90 91 92 93 94 95
	Values(*[]Params) (int64, error)
	ValuesList(*[]ParamsList) (int64, error)
	ValuesFlat(*ParamsList) (int64, error)
	Prepare() (RawPreparer, error)
}

F
FuXiaoHei 已提交
96
// statement querier
S
slene 已提交
97 98 99 100 101 102 103
type stmtQuerier interface {
	Close() error
	Exec(args ...interface{}) (sql.Result, error)
	Query(args ...interface{}) (*sql.Rows, error)
	QueryRow(args ...interface{}) *sql.Row
}

F
FuXiaoHei 已提交
104
// db querier
S
slene 已提交
105 106 107 108 109 110 111
type dbQuerier interface {
	Prepare(query string) (*sql.Stmt, error)
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

F
FuXiaoHei 已提交
112
// transaction beginner
S
slene 已提交
113 114 115 116
type txer interface {
	Begin() (*sql.Tx, error)
}

F
FuXiaoHei 已提交
117
// transaction ending
S
slene 已提交
118 119 120 121 122
type txEnder interface {
	Commit() error
	Rollback() error
}

F
FuXiaoHei 已提交
123
// base database struct
S
slene 已提交
124
type dbBaser interface {
125
	Read(dbQuerier, *modelInfo, reflect.Value, *time.Location, []string) error
126
	Insert(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
S
slene 已提交
127 128
	InsertMulti(dbQuerier, *modelInfo, reflect.Value, int, *time.Location) (int64, error)
	InsertValue(dbQuerier, *modelInfo, bool, []string, []interface{}) (int64, error)
129
	InsertStmt(stmtQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
130
	Update(dbQuerier, *modelInfo, reflect.Value, *time.Location, []string) (int64, error)
131
	Delete(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
132
	ReadBatch(dbQuerier, *querySet, *modelInfo, *Condition, interface{}, *time.Location, []string) (int64, error)
133
	SupportUpdateJoin() bool
134 135 136
	UpdateBatch(dbQuerier, *querySet, *modelInfo, *Condition, Params, *time.Location) (int64, error)
	DeleteBatch(dbQuerier, *querySet, *modelInfo, *Condition, *time.Location) (int64, error)
	Count(dbQuerier, *querySet, *modelInfo, *Condition, *time.Location) (int64, error)
137
	OperatorSql(string) string
138 139
	GenerateOperatorSql(*modelInfo, *fieldInfo, string, []interface{}, *time.Location) (string, []interface{})
	GenerateOperatorLeftCol(*fieldInfo, string, *string)
S
slene 已提交
140
	PrepareInsert(dbQuerier, *modelInfo) (stmtQuerier, string, error)
141
	ReadValues(dbQuerier, *querySet, *modelInfo, *Condition, []string, interface{}, *time.Location) (int64, error)
142 143 144
	MaxLimit() uint64
	TableQuote() string
	ReplaceMarks(*string)
S
slene 已提交
145
	HasReturningID(*modelInfo, *string) bool
146 147
	TimeFromDB(*time.Time, *time.Location)
	TimeToDB(*time.Time, *time.Location)
S
slene 已提交
148
	DbTypes() map[string]string
S
slene 已提交
149 150 151 152 153
	GetTables(dbQuerier) (map[string]bool, error)
	GetColumns(dbQuerier, string) (map[string][3]string, error)
	ShowTablesQuery() string
	ShowColumnsQuery(string) string
	IndexExists(dbQuerier, string, string) bool
154
	collectFieldValue(*modelInfo, *fieldInfo, reflect.Value, bool, *time.Location) (interface{}, error)
S
slene 已提交
155
}