Documentation ¶
Index ¶
- Variables
- func AssignList(entity QueryEntity, output interface{}) error
- func AssignSingle(entity QueryEntity, output interface{}) error
- func List(entity QueryEntity) ([]map[string]string, error)
- func NewQueryEntity(table string, cond QueryCondition, fields ...string) func(resultType ...QueryResultType) QueryEntityResult
- func Query(entity QueryEntity) (interface{}, error)
- func RegisterDBProvider(provideName ProvideEngine, provider DBProvider)
- func RegisterProvider(provideName ProvideEngine, config string) error
- func Single(entity QueryEntity) (map[string]string, error)
- type CondType
- type DBProvider
- type PagerParam
- type ProvideEngine
- type Provider
- type QueryCondition
- type QueryConditionResult
- type QueryEntity
- type QueryEntityResult
- type QueryPagerResult
- type QueryProvider
- type QueryResultType
- type ResultError
- type TranEntity
- type TranEntityResult
- type TranOperate
- type TranProvider
- type TranResult
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidValue = errors.New("Invalid values!")
)
Functions ¶
func AssignList ¶
func AssignList(entity QueryEntity, output interface{}) error
AssignList 将查询结果解析到对应的指针地址 (数据类型包括:[]map[string]string,[]map[string]interface{},[]struct)
func AssignSingle ¶
func AssignSingle(entity QueryEntity, output interface{}) error
AssignSingle 将查询结果解析到对应的指针地址 (数据类型包括:map[string]string,map[string]interface{},struct)
func NewQueryEntity ¶
func NewQueryEntity(table string, cond QueryCondition, fields ...string) func(resultType ...QueryResultType) QueryEntityResult
NewQueryEntity 创建新的查询实体
func Query ¶
func Query(entity QueryEntity) (interface{}, error)
Query 查询数据 (根据QueryResultType返回数据结果类型)
func RegisterDBProvider ¶
func RegisterDBProvider(provideName ProvideEngine, provider DBProvider)
RegisterDBProvider 注册DBProvider
func RegisterProvider ¶
func RegisterProvider(provideName ProvideEngine, config string) error
RegisterProvider 提供全局的provider
Types ¶
type DBProvider ¶
type DBProvider interface { Provider // InitDB 数据库初始化 // config 为配置信息(以json字符串的方式提供) InitDB(config string) error }
DBProvider 提供DB初始化
type PagerParam ¶
PagerParam 分页参数
type ProvideEngine ¶
type ProvideEngine string
ProvideEngine 数据库操作引擎
const ( // MYSQL mysql数据库 MYSQL ProvideEngine = "mysql" )
type Provider ¶
type Provider interface { QueryProvider TranProvider }
Provider 提供统一的数据库操作
var ( // GDAL 提供全局的Provider GDAL Provider )
type QueryCondition ¶
type QueryCondition struct { CType CondType FieldsKv map[string]interface{} Condition string Values []interface{} }
QueryCondition 查询条件
type QueryConditionResult ¶
type QueryConditionResult struct { ResultError Condition QueryCondition }
ConditionResult 提供查询条件处理
func NewCondition ¶
func NewCondition(condition string, values ...interface{}) QueryConditionResult
NewCondition 获取查询条件 condition 查询条件 values 格式化参数
func NewFieldsKvCondition ¶
func NewFieldsKvCondition(fieldsKv interface{}) QueryConditionResult
NewFieldsKvCondition 获取键值查询条件实例 fieldsKv 数据类型(map[string]interface{} or map[string]string or struct) 如果fieldsKv为struct类型,只保留非零值字段
type QueryEntity ¶
type QueryEntity struct { Table string FieldsSelect string Condition QueryCondition ResultType QueryResultType PagerParam PagerParam }
QueryEntity 提供数据查询结构体
type QueryEntityResult ¶
type QueryEntityResult struct { ResultError Entity QueryEntity }
QueryEntityResult 提供查询实体
func NewQueryPagerEntity ¶
func NewQueryPagerEntity(table string, cond QueryCondition, pagerParam PagerParam, fields ...string) QueryEntityResult
NewQueryPagerEntity 创建新的分页查询实体
type QueryPagerResult ¶
type QueryPagerResult struct { Rows []map[string]interface{} `json:"rows"` Total int64 `json:"total"` }
QueryPagerResult 分页查询结果类型
type QueryProvider ¶
type QueryProvider interface { // Single 查询单条数据 Single(QueryEntity) (map[string]string, error) // AssignSingle 将查询结果解析到对应的指针地址 // (数据类型包括:map[string]string,map[string]interface{},struct) AssignSingle(QueryEntity, interface{}) error // List 查询列表数据 List(QueryEntity) ([]map[string]string, error) // AssignList 将查询结果解析到对应的指针地址 // (数据类型包括:[]map[string]string,[]map[string]interface{},[]struct) AssignList(QueryEntity, interface{}) error // Pager 查询分页数据 Pager(QueryEntity) (QueryPagerResult, error) // Query 查询数据(根据QueryResultType返回数据结果类型) Query(QueryEntity) (interface{}, error) }
QueryProvider 提供数据库查询接口
type QueryResultType ¶
type QueryResultType byte
QueryResultType 查询结果类型
const ( // QSingle 单条数据 QSingle QueryResultType = 1 << iota // QList 列表数据 QList // QPager 分页数据 QPager )
type TranEntity ¶
type TranEntity struct { Table string Operate TranOperate FieldsValue map[string]interface{} Condition QueryCondition }
TranEntity 提供事务性操作结构体
type TranEntityResult ¶
type TranEntityResult struct { ResultError Entity TranEntity }
TranEntityResult 提供事务实体
func NewTranAEntity ¶
func NewTranAEntity(table string, fieldsValue interface{}) TranEntityResult
NewTranAEntity 创建新增实体 fieldsValue 数据类型(map[string]interface{} or map[string]string or struct) 如果fieldsValue为struct类型,只保留非零值字段
func NewTranDEntity ¶
func NewTranDEntity(table string, cond QueryCondition) TranEntityResult
NewTranUEntity 创建删除实体
func NewTranUEntity ¶
func NewTranUEntity(table string, fieldsValue interface{}, cond QueryCondition) TranEntityResult
NewTranUEntity 创建更新实体 fieldsValue 数据类型(map[string]interface{} or map[string]string or struct) 如果fieldsValue为struct类型,只保留非零值字段
type TranOperate ¶
type TranOperate byte
TranOperate 操作
const ( // TA 新增 TA TranOperate = 1 << iota // TU 更新 TU // TD 删除 TD )
type TranProvider ¶
type TranProvider interface { // Exec 执行单条事务性操作 Exec(TranEntity) TranResult // ExecTrans 执行多条事务性操作 ExecTrans([]TranEntity) TranResult }
TranProvider 提供数据库事务操作