Documentation ¶
Index ¶
- Variables
- func DecodeColumn(dbData string) map[string][]string
- func DecodeStruct(prtStruct interface{}) map[string]FieldInfo
- func EncodeTag(tag string) (data map[string]string)
- func ExecSql(sql string, args ...interface{}) (affectCount int64, lastInsertId int64, err error)
- func Field2TagMap(fieldInfo map[string]FieldInfo, tag string) map[string]string
- func FieldType(fieldInfo map[string]FieldInfo) map[string]reflect.Type
- func Insert(mo interface{}) (err error)
- func QuerySql(sql string, args ...interface{}) (has bool, data []map[string]interface{}, err error)
- func RegisterDb(connect, driver, link string)
- func RegisterModel(prtModel interface{})
- func RegisterModelCustom(prtModel interface{}, decoder func(prtModel interface{}) ModelInfo)
- func RegisterTranslator(name string, translator Translator)
- func UnDuplicate(src []interface{}) []interface{}
- type Auto
- type Column
- type Config
- type Connect
- type DbDriverMysql
- type FieldInfo
- type InOneSql
- type JsonTran
- type Link
- type ModelInfo
- type Page
- type PreLink
- type ResultKeyMap
- type TimeTran
- type Tran
- type Translator
- type WithModel
- func (p *WithModel) Connect(connect string) *WithModel
- func (p *WithModel) Fields(fields ...string) *WithModel
- func (p *WithModel) FromDbData(isSlice bool, result []map[string]interface{}, ptrSliceModel interface{})
- func (p *WithModel) GetAutoSetField(method string) (needSet map[string]interface{}, err error)
- func (p *WithModel) Insert(prtModel interface{}) (err error)
- func (p *WithModel) Limit(offset, size int) *WithModel
- func (p *WithModel) Link(field string, extCondition string, columns []string) *WithModel
- func (p *WithModel) Select(ptrSliceModel interface{}) (has bool, err error)
- func (p *WithModel) Table(table string) *WithModel
- func (p *WithModel) Where(condition string, args ...interface{}) *WithModel
- func (p *WithModel) WhereIn(condition string, args ...interface{}) *WithModel
- type WithOutModel
- func (p *WithOutModel) Connect(connect string) *WithOutModel
- func (p *WithOutModel) Delete() (affect int64, err error)
- func (p *WithOutModel) ExecSql(sql string, args ...interface{}) (affectCount int64, lastInsertId int64, err error)
- func (p *WithOutModel) Fields(fields ...string) *WithOutModel
- func (p *WithOutModel) First() (result map[string]interface{}, has bool, err error)
- func (p *WithOutModel) GetTable() string
- func (p *WithOutModel) Insert(saveData map[string]interface{}) (id int64, err error)
- func (p *WithOutModel) Limit(offset, size int) *WithOutModel
- func (p *WithOutModel) QuerySql(sql string, args ...interface{}) (result []map[string]interface{}, err error)
- func (p *WithOutModel) Select() (result []map[string]interface{}, has bool, err error)
- func (p *WithOutModel) Table(table string) *WithOutModel
- func (p *WithOutModel) Update(saveData map[string]interface{}) (aff int64, err error)
- func (p *WithOutModel) Where(condition string, args ...interface{}) *WithOutModel
- func (p *WithOutModel) WhereIn(condition string, args ...interface{}) *WithOutModel
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Debug = false
)
View Source
var DefaultDecoder = func(prtModel interface{}) ModelInfo { tag := "orm" fInfo := DecodeStruct(prtModel) table := Field2TagMap(fInfo, "table")["orm"] connect := Field2TagMap(fInfo, "connect")["orm"] fieldMap := Field2TagMap(fInfo, tag) fieldTyp := FieldType(fInfo) field2Db := map[string]string{} autoPk := "" autoFields := map[string]Auto{} trans := map[string]Tran{} links := map[string]Link{} for field, db := range fieldMap { columnTags := DecodeColumn(db) for key, values := range columnTags { switch key { case "pk": if len(values) >= 1 { if values[0] == "auto" { autoPk = field } } case "col": if len(values) >= 1 { field2Db[field] = values[0] } case "tran": if len(values) >= 1 { trans[field] = Tran{ Typ: values[0], } } case "auto": if len(values) >= 2 { autoFields[field] = Auto{ When: values[0], Typ: values[1], } } case "link": if len(values) >= 2 { links[field] = Link{ SelfKey: values[0], LinkKey: values[1], } } } } } m := ModelInfo{ FieldMap: field2Db, AutoPk: autoPk, Table: table, ConnectName: connect, AutoFields: autoFields, FieldTyp: fieldTyp, Trans: trans, Links: links, } return m }
Functions ¶
func DecodeColumn ¶
func DecodeStruct ¶
func Field2TagMap ¶
返回指定tag的string
func RegisterModelCustom ¶
func RegisterModelCustom(prtModel interface{}, decoder func(prtModel interface{}) ModelInfo)
func RegisterTranslator ¶
func RegisterTranslator(name string, translator Translator)
Types ¶
type Connect ¶
type DbDriverMysql ¶
type DbDriverMysql struct {
// contains filtered or unexported fields
}
func Singleton ¶
func Singleton(connect *Connect) (*DbDriverMysql, error)
单例取出db 并返回自己 err 是打开数据库连接的错误
type ResultKeyMap ¶
type Translator ¶
type WithModel ¶
type WithModel struct { WithOutModel // contains filtered or unexported fields }
func (*WithModel) FromDbData ¶
func (p *WithModel) FromDbData(isSlice bool, result []map[string]interface{}, ptrSliceModel interface{})
将从db里取得的map赋值到model里
func (*WithModel) GetAutoSetField ¶
取得在method操作时需要自动填充的字段与值
type WithOutModel ¶
type WithOutModel struct {
// contains filtered or unexported fields
}
func (*WithOutModel) Connect ¶
func (p *WithOutModel) Connect(connect string) *WithOutModel
func (*WithOutModel) Delete ¶
func (p *WithOutModel) Delete() (affect int64, err error)
删除, 注意必须要有where条件
func (*WithOutModel) ExecSql ¶
func (p *WithOutModel) ExecSql(sql string, args ...interface{}) (affectCount int64, lastInsertId int64, err error)
func (*WithOutModel) Fields ¶
func (p *WithOutModel) Fields(fields ...string) *WithOutModel
func (*WithOutModel) First ¶
func (p *WithOutModel) First() (result map[string]interface{}, has bool, err error)
查找并返回一个
func (*WithOutModel) GetTable ¶
func (p *WithOutModel) GetTable() string
func (*WithOutModel) Insert ¶
func (p *WithOutModel) Insert(saveData map[string]interface{}) (id int64, err error)
插入
func (*WithOutModel) Limit ¶
func (p *WithOutModel) Limit(offset, size int) *WithOutModel
func (*WithOutModel) QuerySql ¶
func (p *WithOutModel) QuerySql(sql string, args ...interface{}) (result []map[string]interface{}, err error)
func (*WithOutModel) Select ¶
func (p *WithOutModel) Select() (result []map[string]interface{}, has bool, err error)
查找
func (*WithOutModel) Table ¶
func (p *WithOutModel) Table(table string) *WithOutModel
func (*WithOutModel) Update ¶
func (p *WithOutModel) Update(saveData map[string]interface{}) (aff int64, err error)
更新, 注意必须要有where条件
func (*WithOutModel) Where ¶
func (p *WithOutModel) Where(condition string, args ...interface{}) *WithOutModel
func (*WithOutModel) WhereIn ¶
func (p *WithOutModel) WhereIn(condition string, args ...interface{}) *WithOutModel
condition 条件 eg: `id in (?)`. 注意 必须有(?)占位符, 这其实只是一个帮你拼?占位符的语法糖 args 参数 eg: `1,2,3`. 注意 只能是基础类型, 并不支持切片等, 有多个参数请展开
Source Files ¶
Click to show internal directories.
Click to hide internal directories.