Documentation ¶
Overview ¶
* SQL生成模板 用于根据struct的定义生成update语句和insert语句 规则
1、表名 默认t_stuct的名称(小写,驼峰转 xx_xx) 可以通过setTablePreFix来指定默认的表前缀 可以通过tag Table:""指定表名 2、字段名称 默认字段名称(小写,驼峰转 xx_xx) 可以通过 tag Field:""指定字段名 3、特例 通过tag Option:"" 来指定。 可选值:auto、pk、not 分别表示 自动增长、主健、忽略
Index ¶
- Constants
- func GetColName(field reflect.StructField) string
- type BaseDao
- func (this *BaseDao) Delete(obj utils.Object, cols ...string) (int64, error)
- func (this *BaseDao) Exec(sqltemplate string, objs ...interface{}) (int64, error)
- func (this *BaseDao) ExecSqlBatch(sqls ...string) error
- func (this *BaseDao) Find(obj utils.Object, cols ...string) bool
- func (this *BaseDao) FindBySql(obj utils.Object, sqlTemplate string, args ...interface{}) bool
- func (this *BaseDao) GetSession() *Connection
- func (this *BaseDao) Insert(obj utils.Object) (int64, error)
- func (this *BaseDao) InsertAndUpdate(iobj interface{}, sqltemplate string, args ...interface{}) error
- func (this *BaseDao) InsertBatch(objs []utils.Object) (ids []int64, e error)
- func (this *BaseDao) Query(obj utils.Object, page Page, cols ...string) []interface{}
- func (this *BaseDao) QueryAll(obj utils.Object, cols ...string) []interface{}
- func (this *BaseDao) QueryAllBySql(obj utils.Object, sqlTemplate string, args ...interface{}) []interface{}
- func (this *BaseDao) SetDs(c *DataSource)
- func (this *BaseDao) Update(obj utils.Object, cols ...string) (int64, error)
- func (this *BaseDao) UpdateBatch(objs []utils.Object, cols ...string) (counts []int64, e error)
- type Connection
- func (this *Connection) Begin()
- func (this *Connection) Close()
- func (this *Connection) Commit()
- func (this *Connection) Delete(obj interface{}, col ...string) (id int64, affect int64, err error)
- func (this *Connection) ExeSql(sql string, objs ...interface{}) (id int64, affect int64, err error)
- func (this *Connection) Find(obj interface{}, col ...string) bool
- func (this *Connection) Insert(obj interface{}) (id int64, affect int64, err error)
- func (this *Connection) Query(result interface{}, sql string, objs ...interface{}) bool
- func (this *Connection) QueryByPage(result interface{}, page Page, sql string, objs ...interface{}) []interface{}
- func (this *Connection) Rollback()
- func (this *Connection) SimpleQuery(sql string, obj ...interface{}) bool
- func (this *Connection) Update(obj interface{}, col ...string) (id int64, affect int64, err error)
- type DataSource
- func (this *DataSource) CanAssignableTo(t reflect.Type) bool
- func (this *DataSource) Factory(config string) interface{}
- func (this *DataSource) GetConnection() *Connection
- func (this *DataSource) GetDao() *BaseDao
- func (this *DataSource) GetMapperDao(namespace string) *MapperDao
- func (this *DataSource) Init()
- type MapperDao
- func (this *MapperDao) BeginTransaction()
- func (this *MapperDao) Count(obj utils.Object, id string) int64
- func (this *MapperDao) CountByObj(obj utils.Object, col ...string) int64
- func (this *MapperDao) Delete(obj utils.Object, id string) (int64, error)
- func (this *MapperDao) DeleteByObj(obj utils.Object, col ...string) (int64, error)
- func (this *MapperDao) Exist(obj utils.Object, id string) bool
- func (this *MapperDao) ExistByObj(obj utils.Object, col ...string) bool
- func (this *MapperDao) Find(obj utils.Object, id string) bool
- func (this *MapperDao) FindByObj(obj utils.Object, col ...string) bool
- func (this *MapperDao) FinishTransaction()
- func (this *MapperDao) Insert(obj utils.Object, id string) (int64, error)
- func (this *MapperDao) InsertAuto(obj utils.Object) (int64, error)
- func (this *MapperDao) InsertByObj(obj utils.Object) (int64, error)
- func (this *MapperDao) InsertOrUpdateByExist(obj utils.Object, exitsCols []string, updateCols []string) (int64, error)
- func (this *MapperDao) Query(obj utils.Object, page Page, id string) []interface{}
- func (this *MapperDao) QueryAll(obj utils.Object, id string) []interface{}
- func (this *MapperDao) QueryAllByObj(obj utils.Object, col ...string) []interface{}
- func (this *MapperDao) QueryByObj(obj utils.Object, page Page, col ...string) []interface{}
- func (this *MapperDao) Update(obj utils.Object, id string) (int64, error)
- func (this *MapperDao) UpdateByObj(obj utils.Object, col ...string) (int64, error)
- type MapperFile
- type MapperNode
- type Page
- type SqlTemplate
- func (this *SqlTemplate) CreateDeleteSql(target interface{}, col ...string) (string, []interface{}, error)
- func (this *SqlTemplate) CreateFromWhereSql(target interface{}, col ...string) (string, []interface{}, error)
- func (this *SqlTemplate) CreateInserSql(target interface{}) (string, []interface{}, error)
- func (this *SqlTemplate) CreateQuerySql(target interface{}, col ...string) (string, []interface{}, error)
- func (this *SqlTemplate) CreateUpdateSql(target interface{}, col ...string) (string, []interface{}, error)
- func (this *SqlTemplate) GetInsertSql(target interface{}) (string, []interface{}, error)
- func (this *SqlTemplate) SetTablePrefix(prefix string)
- func (this *SqlTemplate) StructValueToCustomArray(target interface{}, col ...string) ([]interface{}, error)
- type SqltemplateCollect
- type SqltemplateManager
Constants ¶
View Source
const Max_RETRY = 10
最大重试次数
Variables ¶
This section is empty.
Functions ¶
func GetColName ¶
func GetColName(field reflect.StructField) string
Types ¶
type BaseDao ¶
type BaseDao struct {
// contains filtered or unexported fields
}
基础数据操作对象
func (*BaseDao) GetSession ¶
func (this *BaseDao) GetSession() *Connection
func (*BaseDao) InsertAndUpdate ¶
func (this *BaseDao) InsertAndUpdate(iobj interface{}, sqltemplate string, args ...interface{}) error
插入对象,并根据对象的id,更新后续的sql语句,一般为update,其中这个关联id必须是第一个参数
func (*BaseDao) InsertBatch ¶
插入,返回auto id和错误信息
func (*BaseDao) QueryAllBySql ¶
func (*BaseDao) SetDs ¶
func (this *BaseDao) SetDs(c *DataSource)
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
*
数据库 连接包装
func (*Connection) Begin ¶
func (this *Connection) Begin()
func (*Connection) Close ¶
func (this *Connection) Close()
func (*Connection) Commit ¶
func (this *Connection) Commit()
func (*Connection) Delete ¶
func (this *Connection) Delete(obj interface{}, col ...string) (id int64, affect int64, err error)
func (*Connection) ExeSql ¶
func (this *Connection) ExeSql(sql string, objs ...interface{}) (id int64, affect int64, err error)
func (*Connection) Find ¶
func (this *Connection) Find(obj interface{}, col ...string) bool
func (*Connection) Insert ¶
func (this *Connection) Insert(obj interface{}) (id int64, affect int64, err error)
func (*Connection) Query ¶
func (this *Connection) Query(result interface{}, sql string, objs ...interface{}) bool
func (*Connection) QueryByPage ¶
func (this *Connection) QueryByPage(result interface{}, page Page, sql string, objs ...interface{}) []interface{}
func (*Connection) Rollback ¶
func (this *Connection) Rollback()
func (*Connection) SimpleQuery ¶
func (this *Connection) SimpleQuery(sql string, obj ...interface{}) bool
type DataSource ¶
type DataSource struct { DBtype string DBurl string DBuser string DBpassword string DBname string DBmapper string //mapper文件夹 // contains filtered or unexported fields }
*
data source
func (*DataSource) CanAssignableTo ¶
func (this *DataSource) CanAssignableTo(t reflect.Type) bool
func (*DataSource) Factory ¶
func (this *DataSource) Factory(config string) interface{}
func (*DataSource) GetDao ¶
func (this *DataSource) GetDao() *BaseDao
func (*DataSource) GetMapperDao ¶
func (this *DataSource) GetMapperDao(namespace string) *MapperDao
func (*DataSource) Init ¶
func (this *DataSource) Init()
type MapperDao ¶
type MapperDao struct {
// contains filtered or unexported fields
}
func (*MapperDao) BeginTransaction ¶
func (this *MapperDao) BeginTransaction()
func (*MapperDao) CountByObj ¶
func (*MapperDao) DeleteByObj ¶
func (*MapperDao) ExistByObj ¶
func (*MapperDao) FinishTransaction ¶
func (this *MapperDao) FinishTransaction()
func (*MapperDao) InsertAuto ¶
一般的insert只有一条,自动选择一条,如果不存在insert,将使用template来完成插入
func (*MapperDao) InsertOrUpdateByExist ¶
func (this *MapperDao) InsertOrUpdateByExist(obj utils.Object, exitsCols []string, updateCols []string) (int64, error)
插入或更新,当存在数据的时候更新,不存在则插入
func (*MapperDao) QueryAllByObj ¶
func (*MapperDao) QueryByObj ¶
type MapperFile ¶
type MapperFile struct { Name string `yaml:"namespace"` Nodes []MapperNode }
type MapperNode ¶
func (*MapperNode) ToFunction ¶
func (this *MapperNode) ToFunction(namespace string) mapperfunction
type SqlTemplate ¶
type SqlTemplate struct {
// contains filtered or unexported fields
}
func (*SqlTemplate) CreateDeleteSql ¶
func (this *SqlTemplate) CreateDeleteSql(target interface{}, col ...string) (string, []interface{}, error)
func (*SqlTemplate) CreateFromWhereSql ¶
func (this *SqlTemplate) CreateFromWhereSql(target interface{}, col ...string) (string, []interface{}, error)
func (*SqlTemplate) CreateInserSql ¶
func (this *SqlTemplate) CreateInserSql(target interface{}) (string, []interface{}, error)
func (*SqlTemplate) CreateQuerySql ¶
func (this *SqlTemplate) CreateQuerySql(target interface{}, col ...string) (string, []interface{}, error)
func (*SqlTemplate) CreateUpdateSql ¶
func (this *SqlTemplate) CreateUpdateSql(target interface{}, col ...string) (string, []interface{}, error)
*
update 指定的是更新字段 条件按主键,所以一定需要定义主键字段 对于批量更新会做新的方法来完成
func (*SqlTemplate) GetInsertSql ¶
func (this *SqlTemplate) GetInsertSql(target interface{}) (string, []interface{}, error)
func (*SqlTemplate) SetTablePrefix ¶
func (this *SqlTemplate) SetTablePrefix(prefix string)
func (*SqlTemplate) StructValueToCustomArray ¶
func (this *SqlTemplate) StructValueToCustomArray(target interface{}, col ...string) ([]interface{}, error)
type SqltemplateCollect ¶
type SqltemplateCollect map[string]mapperfunction
type SqltemplateManager ¶
type SqltemplateManager struct {
// contains filtered or unexported fields
}
func (*SqltemplateManager) AddCollectFromFile ¶
func (this *SqltemplateManager) AddCollectFromFile(f string)
func (*SqltemplateManager) BuildDao ¶
func (this *SqltemplateManager) BuildDao(ds *DataSource, namespace string) *MapperDao
Click to show internal directories.
Click to hide internal directories.