Documentation
¶
Index ¶
- Constants
- Variables
- func Analysis(element *etree.Element, ctx map[string]any) ([]string, string, []string, []any, error)
- func AnalysisExpr(template string) string
- func AnalysisForTemplate(template string, ctx map[string]any, v any) (string, string, []any, error)
- func AnalysisTemplate(template string, ctx map[string]any) (string, string, []any, error)
- func Args(db reflect.Value, values []reflect.Value) (ctx reflect.Value, args map[string]any, tx reflect.Value, auto bool)
- func BaseTypeKey(v reflect.Value) string
- func DatabaseType(key string, dataType ToDatabase)
- func Element(element *etree.Element, template string, ctx map[string]any) (string, string, []any, error)
- func End(tag string, auto bool, result []reflect.Value, ...)
- func ExecResultMapper(result []reflect.Value, exec sql.Result) (count int64, err error)
- func ForElement(element *etree.Element, template string, ctx map[string]any) (string, string, []any, error)
- func GolangType(key string, dataType ToGolang)
- func IfElement(element *etree.Element, template string, ctx map[string]any) (string, string, []any, error)
- func MapperCheck(fun reflect.Value) (bool, error)
- func Namespace(namespace string) string
- func NullConfig(null any)
- func QueryResultMapper(value reflect.Value, result []reflect.Value)
- func ResultMapping(value any) map[string]string
- func Return(result []reflect.Value) (ret []reflect.Value)
- func SelectCheck(columns []string, resultType any) (bool, error)
- func StatementElement(element *etree.Element, template string, ctx map[string]any) (string, string, []any, error)
- func TimeData(value reflect.Value, data any) error
- func TimeDataPointer(value reflect.Value, data any) error
- func ToDatabaseTime(data any) (any, error)
- func ToDatabaseTimePointer(data any) (any, error)
- func TypeKey(t any) string
- func UnTemplate(template string) string
- type Combine
- type GoBatis
- type MapperFunc
- type Other
- type Politic
- type Slice
- type Sql
- type Struct
- type ToDatabase
- type ToGolang
Constants ¶
const ( MySQL = iota PostgreSQL )
const ( Select = "select" Insert = "insert" Update = "update" Delete = "delete" Mapper = "mapper" For = "for" If = "if" Value = "value" VALUE = "VALUE" Values = "values" VALUES = "VALUES" Where = "where" WHERE = "WHERE" )
Variables ¶
var Null = map[string]bool{ TypeKey(sql.NullInt16{}): true, TypeKey(sql.NullInt32{}): true, TypeKey(sql.NullInt64{}): true, TypeKey(sql.NullFloat64{}): true, TypeKey(sql.NullBool{}): true, TypeKey(sql.NullString{}): true, TypeKey(sql.NullByte{}): true, TypeKey(sql.NullTime{}): true, TypeKey(&sql.NullInt16{}): true, TypeKey(&sql.NullInt32{}): true, TypeKey(&sql.NullInt64{}): true, TypeKey(&sql.NullFloat64{}): true, TypeKey(&sql.NullBool{}): true, TypeKey(&sql.NullString{}): true, TypeKey(&sql.NullByte{}): true, TypeKey(&sql.NullTime{}): true, TypeKey(obj.String{}): true, TypeKey(&obj.String{}): true, }
Null 采用结构体全名模式进行校验 通过判断接口接口实现,对后续的自定义结构体解析处理,和空值处理存在冲突,暂时没有处理冲突,接口判断是强制判定,无法让指针和值类型同时验证成功
Functions ¶
func Analysis ¶
func Analysis(element *etree.Element, ctx map[string]any) ([]string, string, []string, []any, error)
Analysis 解析xml标签
func AnalysisForTemplate ¶
AnalysisForTemplate 解析 for 标签的 文本模板 template for标签下的文本内容 ctx 并不是全局的上下文数据,如果 for循环的 item是个 obj ,则ctx将表示 obj v 如果 for循环的 item是个 基本类型 v 将代表它
func AnalysisTemplate ¶
AnalysisTemplate 模板解析器
func Args ¶
func Args(db reflect.Value, values []reflect.Value) (ctx reflect.Value, args map[string]any, tx reflect.Value, auto bool)
Args 参数赋值处理 处理定义函数的入参,返回一个参数序列给到后面的函数调用入参
func BaseTypeKey ¶
BaseTypeKey 通过 BaseTypeKey 得到的变量默认全包名对泛型参数进行特殊处理的,不会加上类型中的 [xxx]定义部分信息
func DatabaseType ¶
func DatabaseType(key string, dataType ToDatabase)
DatabaseType 对外提供添加 自定义sql语句数据类型解析支持
func ExecResultMapper ¶
ExecResultMapper SQL执行结果赋值 规则: insert,update,delete,默认第一个返回值为 执行sql 影响的具体行数 insert 第二个返回参数是 自增长主键
func ForElement ¶
func GolangType ¶
GolangType 对外提供添加 自定义结果集数据类型解析支持 key 需要通过 TypeKey 函数获取一个全局唯一的标识符 dataType 需要提供 对应数据解析逻辑细节可以参考 TimeData 或者 TimeDataPointer
func MapperCheck ¶
MapperCheck 检查 不同类别的sql标签 Mapper 函数是否符合规范 规则: 入参只能有一个并且只能是 map 或者 结构体,对返回值最后一个参数必须是error
func NullConfig ¶ added in v0.2.2
func NullConfig(null any)
NullConfig 添加 null 数据 null 数据不会被 databaseToGolang 映射函数处理,相应的如果要在自定义空值中处理特殊的赋值逻辑,通过Scan 接口也可以实现,例如obj.String中处理逻辑 obj.String 做了对 普通字符串和数据库时间类型的通用匹配
type String struct { V string } func (s *String) Scan(data any) error { if data != nil { switch data.(type) { case time.Time: s.V = data.(time.Time).Format("2006-01-02 15:04:05") case string: s.V = data.(string) case []byte: s.V = string(data.([]byte)) } } return nil }
参考 obj/string.go
func QueryResultMapper ¶
QueryResultMapper SQL 查询结果赋值 value 对应查询结果集 result 对应mapper函数返回值
func ResultMapping ¶
ResultMapping 解析结构体上的column标签 生成 数据库字段 到 结构体字段名 的映射匹配 value 如果传递的是结构体,则会解析对应的 column 标签 或者字段本身 value 如果是 map 则不会做任何处理,返回 nil
func StatementElement ¶
func ToDatabaseTime ¶
func ToDatabaseTimePointer ¶
func UnTemplate ¶
UnTemplate 解析 {xx} 模板 解析为三个部分 ["{","xx","}"]
Types ¶
type GoBatis ¶
type GoBatis struct { *zap.Logger // SqlSource 用于保存 xml 配置的文件的根路径配置信息,Build会通过SqlSource属性去加载 xml 文件 SqlSource string // NameSpaces 保存了每个 xml 配置的根元素构建出来的 Sql 对象 NameSpaces map[string]*Sql Type int // contains filtered or unexported fields }
func (*GoBatis) LoadByRootPath ¶ added in v0.3.1
LoadByRootPath 根据提供的更路径及其 files 加载 mapper 文件 {root:表示根路径,根路径应该和提供的 files 嵌入文件资源对应}
type Politic ¶
type Politic interface { // ForEach value 待处理迭代的数据 ctx 上下文数据 item 上下文数据key序列 ForEach(value any, template string, separator string) (string, string, []any, error) }
Politic for 标签迭代实现接口扩展 标准切片之外的 List 数据支持
type Sql ¶
type Sql struct { // Element 表示 一个 Mapper 文件的更元素 Element *etree.Element // Statement 表示每个 更元素下面的 sql语句标签 Statement map[string]*etree.Element }
Sql 单个xml的解析结构
func (*Sql) LoadSqlElement ¶
func (receiver *Sql) LoadSqlElement()
type ToDatabase ¶
ToDatabase mapper 中sql解析模板对应的复杂数据据类型解析器 data : 对应的数据本身 对应需要返回一个非结构体的基础数据类型(int float,bool,string) 更具需要构成的实际sql决定,后续的sql解析将自动匹配数据类