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

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

S
slene 已提交
9 10 11 12 13
type Driver interface {
	Name() string
	Type() DriverType
}

S
slene 已提交
14 15 16 17 18
type Fielder interface {
	String() string
	FieldType() int
	SetRaw(interface{}) error
	RawValue() interface{}
S
slene 已提交
19
	Clean() error
S
slene 已提交
20 21 22
}

type Ormer interface {
23 24 25 26 27 28 29
	Read(interface{}) error
	Insert(interface{}) (int64, error)
	Update(interface{}) (int64, error)
	Delete(interface{}) (int64, error)
	M2mAdd(interface{}, string, ...interface{}) (int64, error)
	M2mDel(interface{}, string, ...interface{}) (int64, error)
	LoadRel(interface{}, string) (int64, error)
S
slene 已提交
30 31 32 33 34 35
	QueryTable(interface{}) QuerySeter
	Using(string) error
	Begin() error
	Commit() error
	Rollback() error
	Raw(string, ...interface{}) RawSeter
S
slene 已提交
36
	Driver() Driver
S
slene 已提交
37 38 39
}

type Inserter interface {
40
	Insert(interface{}) (int64, error)
S
slene 已提交
41 42 43 44 45 46
	Close() error
}

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

type RawPreparer interface {
64
	Exec(...interface{}) (sql.Result, error)
S
slene 已提交
65 66 67 68
	Close() error
}

type RawSeter interface {
69
	Exec() (sql.Result, error)
S
slene 已提交
70 71 72
	QueryRow(...interface{}) error
	QueryRows(...interface{}) (int64, error)
	SetArgs(...interface{}) RawSeter
S
slene 已提交
73 74 75 76 77 78
	Values(*[]Params) (int64, error)
	ValuesList(*[]ParamsList) (int64, error)
	ValuesFlat(*ParamsList) (int64, error)
	Prepare() (RawPreparer, error)
}

S
slene 已提交
79 80 81 82 83 84 85 86 87 88 89
type IFieldError interface {
	Name() string
	Error() error
}

type IFieldErrors interface {
	Get(string) IFieldError
	Set(string, IFieldError)
	List() []IFieldError
}

S
slene 已提交
90 91 92 93 94 95 96
type stmtQuerier interface {
	Close() error
	Exec(args ...interface{}) (sql.Result, error)
	Query(args ...interface{}) (*sql.Rows, error)
	QueryRow(args ...interface{}) *sql.Row
}

S
slene 已提交
97 98 99 100 101 102 103
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
}

S
slene 已提交
104 105 106 107 108 109 110 111 112
type txer interface {
	Begin() (*sql.Tx, error)
}

type txEnder interface {
	Commit() error
	Rollback() error
}

S
slene 已提交
113
type dbBaser interface {
114 115 116 117 118 119
	Read(dbQuerier, *modelInfo, reflect.Value, *time.Location) error
	Insert(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
	InsertStmt(stmtQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
	Update(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
	Delete(dbQuerier, *modelInfo, reflect.Value, *time.Location) (int64, error)
	ReadBatch(dbQuerier, *querySet, *modelInfo, *Condition, interface{}, *time.Location) (int64, error)
120
	SupportUpdateJoin() bool
121 122 123
	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)
124
	OperatorSql(string) string
125 126
	GenerateOperatorSql(*modelInfo, *fieldInfo, string, []interface{}, *time.Location) (string, []interface{})
	GenerateOperatorLeftCol(*fieldInfo, string, *string)
S
slene 已提交
127
	PrepareInsert(dbQuerier, *modelInfo) (stmtQuerier, string, error)
128
	ReadValues(dbQuerier, *querySet, *modelInfo, *Condition, []string, interface{}, *time.Location) (int64, error)
129 130 131
	MaxLimit() uint64
	TableQuote() string
	ReplaceMarks(*string)
S
slene 已提交
132
	HasReturningID(*modelInfo, *string) bool
133 134
	TimeFromDB(*time.Time, *time.Location)
	TimeToDB(*time.Time, *time.Location)
S
slene 已提交
135
	DbTypes() map[string]string
S
slene 已提交
136 137 138 139 140
	GetTables(dbQuerier) (map[string]bool, error)
	GetColumns(dbQuerier, string) (map[string][3]string, error)
	ShowTablesQuery() string
	ShowColumnsQuery(string) string
	IndexExists(dbQuerier, string, string) bool
S
slene 已提交
141
}