Documentation ¶
Overview ¶
数据库ORM.
Index ¶
- Constants
- func AddConfigGroup(group string, nodes ConfigGroup)
- func AddConfigNode(group string, node ConfigNode)
- func AddDefaultConfigGroup(nodes ConfigGroup)
- func AddDefaultConfigNode(node ConfigNode)
- func SetConfig(c Config)
- func SetDefaultGroup(groupName string)
- type Config
- type ConfigGroup
- type ConfigNode
- type Db
- func (db *Db) BatchInsert(table string, list List, batch int) (sql.Result, error)
- func (db *Db) BatchReplace(table string, list List, batch int) (sql.Result, error)
- func (db *Db) BatchSave(table string, list List, batch int) (sql.Result, error)
- func (db *Db) Begin() (*Tx, error)
- func (db *Db) Close() error
- func (db *Db) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error)
- func (db *Db) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *Db) From(tables string) *Model
- func (db *Db) GetAll(query string, args ...interface{}) (Result, error)
- func (db *Db) GetCount(query string, args ...interface{}) (int, error)
- func (db *Db) GetOne(query string, args ...interface{}) (Record, error)
- func (db *Db) GetStruct(obj interface{}, query string, args ...interface{}) error
- func (db *Db) GetValue(query string, args ...interface{}) (Value, error)
- func (db *Db) Insert(table string, data Map) (sql.Result, error)
- func (db *Db) PingMaster() error
- func (db *Db) PingSlave() error
- func (db *Db) Prepare(query string) (*sql.Stmt, error)
- func (db *Db) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *Db) Replace(table string, data Map) (sql.Result, error)
- func (db *Db) Save(table string, data Map) (sql.Result, error)
- func (db *Db) Select(tables, fields string, condition interface{}, groupBy, orderBy string, ...) (Result, error)
- func (db *Db) SetMaxIdleConns(n int)
- func (db *Db) SetMaxOpenConns(n int)
- func (db *Db) Table(tables string) *Model
- func (db *Db) Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error)
- type Link
- type List
- type Map
- type Model
- func (md *Model) All() (Result, error)
- func (md *Model) And(where interface{}, args ...interface{}) *Model
- func (md *Model) Batch(batch int) *Model
- func (md *Model) Count() (int, error)
- func (md *Model) Data(data ...interface{}) *Model
- func (md *Model) Delete() (sql.Result, error)
- func (md *Model) Fields(fields string) *Model
- func (md *Model) GroupBy(groupBy string) *Model
- func (md *Model) InnerJoin(joinTable string, on string) *Model
- func (md *Model) Insert() (sql.Result, error)
- func (md *Model) LeftJoin(joinTable string, on string) *Model
- func (md *Model) Limit(start int, limit int) *Model
- func (md *Model) One() (Record, error)
- func (md *Model) Or(where interface{}, args ...interface{}) *Model
- func (md *Model) OrderBy(orderBy string) *Model
- func (md *Model) Replace() (sql.Result, error)
- func (md *Model) RightJoin(joinTable string, on string) *Model
- func (md *Model) Save() (sql.Result, error)
- func (md *Model) Select() (Result, error)
- func (md *Model) Struct(obj interface{}) error
- func (md *Model) Update() (sql.Result, error)
- func (md *Model) Value() (Value, error)
- func (md *Model) Where(where interface{}, args ...interface{}) *Model
- type Record
- type Result
- func (r Result) ToIntMap(key string) map[int]Map
- func (r Result) ToIntRecord(key string) map[int]Record
- func (r Result) ToList() List
- func (r Result) ToStringMap(key string) map[string]Map
- func (r Result) ToStringRecord(key string) map[string]Record
- func (r Result) ToUintMap(key string) map[uint]Map
- func (r Result) ToUintRecord(key string) map[uint]Record
- type Tx
- func (tx *Tx) BatchInsert(table string, list List, batch int) (sql.Result, error)
- func (tx *Tx) BatchReplace(table string, list List, batch int) (sql.Result, error)
- func (tx *Tx) BatchSave(table string, list List, batch int) (sql.Result, error)
- func (tx *Tx) Commit() error
- func (tx *Tx) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error)
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) From(tables string) *Model
- func (tx *Tx) GetAll(query string, args ...interface{}) (Result, error)
- func (tx *Tx) GetCount(query string, args ...interface{}) (int, error)
- func (tx *Tx) GetOne(query string, args ...interface{}) (Record, error)
- func (tx *Tx) GetStruct(obj interface{}, query string, args ...interface{}) error
- func (tx *Tx) GetValue(query string, args ...interface{}) (Value, error)
- func (tx *Tx) Insert(table string, data Map) (sql.Result, error)
- func (tx *Tx) Prepare(query string) (*sql.Stmt, error)
- func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Tx) Replace(table string, data Map) (sql.Result, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) Save(table string, data Map) (sql.Result, error)
- func (tx *Tx) Select(tables, fields string, condition interface{}, groupBy, orderBy string, ...) (Result, error)
- func (tx *Tx) Table(tables string) *Model
- func (tx *Tx) Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error)
- type Value
- func (v Value) Bool() bool
- func (v Value) Bytes() []byte
- func (v Value) Float32() float32
- func (v Value) Float64() float64
- func (v Value) Int() int
- func (v Value) Int16() int16
- func (v Value) Int32() int32
- func (v Value) Int64() int64
- func (v Value) Int8() int8
- func (v Value) String() string
- func (v Value) Time() time.Time
- func (v Value) TimeDuration() time.Duration
- func (v Value) Uint() uint
- func (v Value) Uint16() uint16
- func (v Value) Uint32() uint32
- func (v Value) Uint64() uint64
- func (v Value) Uint8() uint8
Constants ¶
View Source
const ( OPTION_INSERT = 0 OPTION_REPLACE = 1 OPTION_SAVE = 2 OPTION_IGNORE = 3 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfigNode ¶
type ConfigNode struct { Host string // 地址 Port string // 端口 User string // 账号 Pass string // 密码 Name string // 数据库名称 Type string // 数据库类型:mysql, sqlite, mssql, pgsql, oracle(目前仅支持mysql) Role string // (可选,默认为master)数据库的角色,用于主从操作分离,至少需要有一个master,参数值:master, slave Charset string // (可选,默认为 utf8)编码,默认为 utf8 Priority int // (可选)用于负载均衡的权重计算,当集群中只有一个节点时,权重没有任何意义 Linkinfo string // (可选)自定义链接信息,当该字段被设置值时,以上链接字段(Host,Port,User,Pass,Name)将失效(该字段是一个扩展功能) }
数据库单项配置
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
数据库链接对象
func (*Db) BatchInsert ¶
CURD操作:批量数据指定批次量写入
func (*Db) BatchReplace ¶
CURD操作:批量数据指定批次量写入, 如果数据存在(主键或者唯一索引),那么删除后重新写入一条
type Link ¶
type Link interface { // 打开数据库连接,建立数据库操作对象 Open(c *ConfigNode) (*sql.DB, error) // SQL操作方法 Query(q string, args ...interface{}) (*sql.Rows, error) Exec(q string, args ...interface{}) (sql.Result, error) Prepare(q string) (*sql.Stmt, error) // 数据库查询 GetAll(q string, args ...interface{}) (Result, error) GetOne(q string, args ...interface{}) (Record, error) GetValue(q string, args ...interface{}) (Value, error) // Ping PingMaster() error PingSlave() error // 连接属性设置 SetMaxIdleConns(n int) SetMaxOpenConns(n int) // 开启事务操作 Begin() (*Tx, error) // 数据表插入/更新/保存操作 Insert(table string, data Map) (sql.Result, error) Replace(table string, data Map) (sql.Result, error) Save(table string, data Map) (sql.Result, error) // 数据表插入/更新/保存操作(批量) BatchInsert(table string, list List, batch int) (sql.Result, error) BatchReplace(table string, list List, batch int) (sql.Result, error) BatchSave(table string, list List, batch int) (sql.Result, error) // 数据修改/删除 Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error) // 创建链式操作对象(Table为From的别名) Table(tables string) *Model From(tables string) *Model // 关闭数据库操作对象 Close() error // contains filtered or unexported methods }
数据库操作接口
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
数据库链式操作模型对象
func (*Model) Count ¶
链式操作,查询数量,fields可以为空,也可以自定义查询字段, 当给定自定义查询字段时,该字段必须为数量结果,否则会引起歧义,如:Fields("COUNT(id)")
type Result ¶
type Result []Record
返回数据表记录List
func (Result) ToIntRecord ¶
将结果列表按照指定的字段值做map[int]Record
func (Result) ToStringMap ¶
将结果列表按照指定的字段值做map[string]Map
func (Result) ToStringRecord ¶
将结果列表按照指定的字段值做map[string]Record
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
数据库事务对象
func (*Tx) BatchInsert ¶
CURD操作:批量数据指定批次量写入
func (*Tx) BatchReplace ¶
CURD操作:批量数据指定批次量写入, 如果数据存在(主键或者唯一索引),那么删除后重新写入一条
Click to show internal directories.
Click to hide internal directories.