Documentation
¶
Index ¶
- Constants
- func Asc(field string) string
- func AssignMap(obj Model, m map[string]interface{})
- func AssignMapByField(obj Model, m map[string]interface{})
- func AssignSlice(obj Model, values []interface{})
- func AssignStruct(obj Model, target interface{})
- func Col(args ...string) string
- func Desc(field string) string
- func Export(obj Model) map[string]interface{}
- func InToSql(field string, len int, negative bool) string
- func LoadConf(path string)
- func Marry(marry int) string
- func MkQueryHolder(size int) string
- func PkValid(obj Model) bool
- type Conditions
- func (this *Conditions) And(sql string, params ...interface{}) *Conditions
- func (this *Conditions) IsEmpty() bool
- func (this *Conditions) Push(marry int, sql string, params ...interface{}) *Conditions
- func (this *Conditions) PushParams(params ...interface{}) *Conditions
- func (this *Conditions) PushSQL(marry int, sql string) *Conditions
- type Connection
- func (this *Connection) Delete(query *QueryBuilder) *ExecResult
- func (this *Connection) Exec(t QueryType, sql string, params ...interface{}) *ExecResult
- func (this *Connection) Find(query *QueryBuilder) *ResultSet
- func (this *Connection) GetDB() (*sql.DB, error)
- func (this *Connection) GetErr() error
- func (this *Connection) GetName() string
- func (this *Connection) HasErr() bool
- func (this *Connection) Insert(query *QueryBuilder) *ExecResult
- func (this *Connection) IsConn() bool
- func (this *Connection) Query(sql string, params ...interface{}) *ResultSet
- func (this *Connection) Update(query *QueryBuilder) *ExecResult
- type EventSignal
- type ExecResult
- type Model
- type ModelColumn
- type ModelEvents
- func (this *ModelEvents) AfterCreate()
- func (this *ModelEvents) AfterDestroy()
- func (this *ModelEvents) AfterSave()
- func (this *ModelEvents) AfterUpdate()
- func (this *ModelEvents) BeforeCreate() EventSignal
- func (this *ModelEvents) BeforeDestroy() EventSignal
- func (this *ModelEvents) BeforeSave() EventSignal
- func (this *ModelEvents) BeforeUpdate() EventSignal
- func (this *ModelEvents) OnBind()
- type ModelMapping
- type Ope
- type PkMode
- type QueryBuilder
- func (this *QueryBuilder) ClearValues() *QueryBuilder
- func (this *QueryBuilder) Cols(columns ...string) *QueryBuilder
- func (this *QueryBuilder) Find(obj Model) *ResultSet
- func (this *QueryBuilder) FindOne(obj Model) *ResultSet
- func (this *QueryBuilder) GetExecSQLParams() (string, []interface{})
- func (this *QueryBuilder) GetInsertSize() int
- func (this *QueryBuilder) GetJoinColumns() string
- func (this *QueryBuilder) GetParams() []interface{}
- func (this *QueryBuilder) GetQueryName() string
- func (this *QueryBuilder) GetQueryType() QueryType
- func (this *QueryBuilder) GetSQL() string
- func (this *QueryBuilder) Group(column string) *QueryBuilder
- func (this *QueryBuilder) HasConds() bool
- func (this *QueryBuilder) In(field string, values ...interface{}) *QueryBuilder
- func (this *QueryBuilder) Limit(limit int) *QueryBuilder
- func (this *QueryBuilder) NotIn(field string, values ...interface{}) *QueryBuilder
- func (this *QueryBuilder) Offset(offset int, limit int) *QueryBuilder
- func (this *QueryBuilder) OrIn(field string, values ...interface{}) *QueryBuilder
- func (this *QueryBuilder) OrNotIn(field string, values ...interface{}) *QueryBuilder
- func (this *QueryBuilder) OrWhere(sql string, params ...interface{}) *QueryBuilder
- func (this *QueryBuilder) Order(args ...string) *QueryBuilder
- func (this *QueryBuilder) Set(key string, value interface{}) *QueryBuilder
- func (this *QueryBuilder) SetCols(columns ...string) *QueryBuilder
- func (this *QueryBuilder) SetMap(values map[string]interface{}) *QueryBuilder
- func (this *QueryBuilder) Table(args ...string) *QueryBuilder
- func (this *QueryBuilder) Values(values ...interface{}) *QueryBuilder
- func (this *QueryBuilder) Verify() error
- func (this *QueryBuilder) Where(sql string, params ...interface{}) *QueryBuilder
- type QueryType
- type ResultRow
- func (this *ResultRow) Bool(field string) bool
- func (this *ResultRow) Compare(values map[string]interface{}) map[string]interface{}
- func (this *ResultRow) Fetch(obj Model) Model
- func (this *ResultRow) Float(field string) float64
- func (this *ResultRow) Get(f string) []byte
- func (this *ResultRow) GetRow() *ResultRow
- func (this *ResultRow) Int(field string) int
- func (this *ResultRow) Int64(field string) int64
- func (this *ResultRow) IntTime(field string) time.Time
- func (this *ResultRow) IsExists() bool
- func (this *ResultRow) IsNew() bool
- func (this *ResultRow) Round(field string, places int) float64
- func (this *ResultRow) Str(f string) string
- type ResultSet
- func (this *ResultSet) AddRow(rawBytes [][]byte, error error)
- func (this *ResultSet) ColumnOf(field string) int
- func (this *ResultSet) Count() int
- func (this *ResultSet) Each(fn func(int, *ResultRow)) *ResultSet
- func (this *ResultSet) GetErr() error
- func (this *ResultSet) HasErr() bool
- func (this *ResultSet) IsEmpty() bool
- func (this *ResultSet) Row(index int) *ResultRow
- func (this *ResultSet) Rows() []*ResultRow
- type State
- type XmlConfig
- type XmlDb
- type XmlDbOps
Constants ¶
View Source
const ( TagColumn = "col" TagPk = "pk" TagOn = "on" TagValNothing = "" TagValPkAi = "ai" TagValPkNormal = "nor" OnCreate = "create" OnUpdate = "update" )
View Source
const ( EventBreak = false EventContinue = true )
View Source
const ( MARRY_AND = iota MARRY_OR )
View Source
const ( SQL_AND = "AND" SQL_OR = "OR" SQL_ASC = "ASC" SQL_DESC = "DESC" SQL_AS = "AS" SQL_NONE = "" SQL_QUERY = "?" SQL_COL_SPR = "," SQL_QUERY_HOLDER = SQL_COL_SPR + SQL_QUERY SQL_IN = "IN" SQL_NOT_IN = "NOT IN" )
View Source
const ( T_STR = iota T_INT T_FLOAT )
Variables ¶
This section is empty.
Functions ¶
func AssignMapByField ¶
func AssignSlice ¶
func AssignSlice(obj Model, values []interface{})
func AssignStruct ¶
func AssignStruct(obj Model, target interface{})
func MkQueryHolder ¶
Types ¶
type Conditions ¶
type Conditions struct {
SQL string
Params []interface{}
}
func (*Conditions) And ¶
func (this *Conditions) And(sql string, params ...interface{}) *Conditions
func (*Conditions) IsEmpty ¶
func (this *Conditions) IsEmpty() bool
func (*Conditions) Push ¶
func (this *Conditions) Push(marry int, sql string, params ...interface{}) *Conditions
func (*Conditions) PushParams ¶
func (this *Conditions) PushParams(params ...interface{}) *Conditions
func (*Conditions) PushSQL ¶
func (this *Conditions) PushSQL(marry int, sql string) *Conditions
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func Conn ¶
func Conn(name string) *Connection
func (*Connection) Delete ¶
func (this *Connection) Delete(query *QueryBuilder) *ExecResult
func (*Connection) Exec ¶
func (this *Connection) Exec(t QueryType, sql string, params ...interface{}) *ExecResult
func (*Connection) Find ¶
func (this *Connection) Find(query *QueryBuilder) *ResultSet
func (*Connection) GetErr ¶
func (this *Connection) GetErr() error
func (*Connection) GetName ¶
func (this *Connection) GetName() string
func (*Connection) HasErr ¶
func (this *Connection) HasErr() bool
func (*Connection) Insert ¶
func (this *Connection) Insert(query *QueryBuilder) *ExecResult
func (*Connection) IsConn ¶
func (this *Connection) IsConn() bool
func (*Connection) Query ¶
func (this *Connection) Query(sql string, params ...interface{}) *ResultSet
func (*Connection) Update ¶
func (this *Connection) Update(query *QueryBuilder) *ExecResult
type EventSignal ¶
type EventSignal bool
type ExecResult ¶
func NewExecResult ¶
func NewExecResult(t QueryType, rs sql.Result, err error) *ExecResult
func (*ExecResult) ExecError ¶
func (this *ExecResult) ExecError() error
func (*ExecResult) ExecHasError ¶
func (this *ExecResult) ExecHasError() bool
func (*ExecResult) IsCreate ¶
func (this *ExecResult) IsCreate() bool
func (*ExecResult) IsDelete ¶
func (this *ExecResult) IsDelete() bool
func (*ExecResult) IsSave ¶
func (this *ExecResult) IsSave() bool
func (*ExecResult) IsSuccess ¶
func (this *ExecResult) IsSuccess() bool
func (*ExecResult) IsUpdate ¶
func (this *ExecResult) IsUpdate() bool
type Model ¶
type Model interface {
GetRow() *ResultRow
Conn() *Connection
Table() string
IsExists() bool
IsNew() bool
// Event Api
OnBind() // 增加一个OnBind接口
BeforeUpdate() EventSignal
BeforeCreate() EventSignal
BeforeSave() EventSignal
BeforeDestroy() EventSignal
AfterUpdate()
AfterCreate()
AfterSave()
AfterDestroy()
}
type ModelColumn ¶
type ModelEvents ¶
type ModelEvents struct {
}
func (*ModelEvents) AfterCreate ¶
func (this *ModelEvents) AfterCreate()
func (*ModelEvents) AfterDestroy ¶
func (this *ModelEvents) AfterDestroy()
func (*ModelEvents) AfterSave ¶
func (this *ModelEvents) AfterSave()
func (*ModelEvents) AfterUpdate ¶
func (this *ModelEvents) AfterUpdate()
func (*ModelEvents) BeforeCreate ¶
func (this *ModelEvents) BeforeCreate() EventSignal
func (*ModelEvents) BeforeDestroy ¶
func (this *ModelEvents) BeforeDestroy() EventSignal
func (*ModelEvents) BeforeSave ¶
func (this *ModelEvents) BeforeSave() EventSignal
func (*ModelEvents) BeforeUpdate ¶
func (this *ModelEvents) BeforeUpdate() EventSignal
func (*ModelEvents) OnBind ¶
func (this *ModelEvents) OnBind()
type ModelMapping ¶
type ModelMapping struct {
// 主键的字段,实际上指向的是一个ModelColumn
Pk *ModelColumn
// 主键的模式
PkMode PkMode
// 映射的字段
Columns []*ModelColumn
// 字段的总数
Size int
}
func GetModelMapping ¶
func GetModelMapping(obj Model) *ModelMapping
type QueryBuilder ¶
type QueryBuilder struct {
//////////////////////////////////////////
// 关联的字段,只在Select和Insert中有效
Columns []string
// 要操作的目标的表
// select时,为查询的表,不包含join的表
// insert, update, delete为操作的主表
TargetTable string
// 查询条件
Conditions *Conditions
// limit, 0 -> offset, 1 -> limit
LimitOffset [2]int
// 排序字段
OrderColumns []string
// GROUP BY
GroupColumn string
//////////////////////////////////////////
// Insert
InsertData [][]interface{}
//////////////////////////////////////////
// Update
UpdateData map[string]interface{}
// contains filtered or unexported fields
}
func Delete ¶
func Delete(table string) *QueryBuilder
func Insert ¶
func Insert(table string) *QueryBuilder
func Update ¶
func Update(table string) *QueryBuilder
func (*QueryBuilder) ClearValues ¶
func (this *QueryBuilder) ClearValues() *QueryBuilder
func (*QueryBuilder) Find ¶
func (this *QueryBuilder) Find(obj Model) *ResultSet
func (*QueryBuilder) FindOne ¶
func (this *QueryBuilder) FindOne(obj Model) *ResultSet
将FindOne绑定到QueryBuilder,这样更符合语义化 adm.Select().Where("id > 100").FindOne()
func (*QueryBuilder) GetExecSQLParams ¶
func (this *QueryBuilder) GetExecSQLParams() (string, []interface{})
func (*QueryBuilder) GetInsertSize ¶
func (this *QueryBuilder) GetInsertSize() int
func (*QueryBuilder) GetJoinColumns ¶
func (this *QueryBuilder) GetJoinColumns() string
func (*QueryBuilder) GetParams ¶
func (this *QueryBuilder) GetParams() []interface{}
go 1.4.2 这里返回一个nil会自动转为一个 [] 空数组
func (*QueryBuilder) GetQueryName ¶
func (this *QueryBuilder) GetQueryName() string
func (*QueryBuilder) GetQueryType ¶
func (this *QueryBuilder) GetQueryType() QueryType
func (*QueryBuilder) GetSQL ¶
func (this *QueryBuilder) GetSQL() string
func (*QueryBuilder) Group ¶
func (this *QueryBuilder) Group(column string) *QueryBuilder
暂时只支持一个字段的Group
func (*QueryBuilder) HasConds ¶
func (this *QueryBuilder) HasConds() bool
func (*QueryBuilder) In ¶
func (this *QueryBuilder) In(field string, values ...interface{}) *QueryBuilder
func (*QueryBuilder) Limit ¶
func (this *QueryBuilder) Limit(limit int) *QueryBuilder
func (*QueryBuilder) NotIn ¶
func (this *QueryBuilder) NotIn(field string, values ...interface{}) *QueryBuilder
func (*QueryBuilder) Offset ¶
func (this *QueryBuilder) Offset(offset int, limit int) *QueryBuilder
func (*QueryBuilder) OrIn ¶
func (this *QueryBuilder) OrIn(field string, values ...interface{}) *QueryBuilder
func (*QueryBuilder) OrNotIn ¶
func (this *QueryBuilder) OrNotIn(field string, values ...interface{}) *QueryBuilder
func (*QueryBuilder) OrWhere ¶
func (this *QueryBuilder) OrWhere(sql string, params ...interface{}) *QueryBuilder
func (*QueryBuilder) Order ¶
func (this *QueryBuilder) Order(args ...string) *QueryBuilder
func (*QueryBuilder) Set ¶
func (this *QueryBuilder) Set(key string, value interface{}) *QueryBuilder
func (*QueryBuilder) SetCols ¶
func (this *QueryBuilder) SetCols(columns ...string) *QueryBuilder
直接覆盖现有的所有字段
func (*QueryBuilder) SetMap ¶
func (this *QueryBuilder) SetMap(values map[string]interface{}) *QueryBuilder
func (*QueryBuilder) Values ¶
func (this *QueryBuilder) Values(values ...interface{}) *QueryBuilder
func (*QueryBuilder) Verify ¶
func (this *QueryBuilder) Verify() error
func (*QueryBuilder) Where ¶
func (this *QueryBuilder) Where(sql string, params ...interface{}) *QueryBuilder
type ResultRow ¶
type ResultRow struct {
Error error
// contains filtered or unexported fields
}
type State ¶
type State int8
type XmlDb ¶
type XmlDb struct {
XMLName xml.Name `xml:"database"`
DSN string `xml:"dsn,attr"`
Name string `xml:"name,attr"`
Host string `xml:"host"`
Port int `xml:"port"`
Db string `xml:"db"`
User string `xml:"user"`
Password string `xml:"password"`
MaxConn int `xml:"maxConn"`
MaxIdle int `xml:"maxIdle"`
Charset string `xml:"charset"`
Options []XmlDbOps `xml:"option"`
}
func (*XmlDb) GetCharset ¶
func (*XmlDb) GetConnDSN ¶
Click to show internal directories.
Click to hide internal directories.