Documentation ¶
Index ¶
- Variables
- func AddDataTypeFunc(dataType string, fun dataTypeFun)
- func Convert(r *rawTable, ptr any) (err error)
- func ConvertColIndex(r *rawTable, colIndex int, ptr any) (err error)
- func ConvertColName(r *rawTable, colName string, ptr any) (err error)
- func ConvertToString(val any) string
- func ConvertToStringSlice(val any) []string
- func DeleteByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
- func Exist(ctx context.Context, t Table) (bool, error)
- func GetContextDBConn(ctx context.Context) *sql.DB
- func GetContextTxConn(ctx context.Context) *sql.Tx
- func GetContextTxOptions(ctx context.Context) *sql.TxOptions
- func GetPkColumnName(ctx context.Context) string
- func Hump(column string) (filed string)
- func Insert(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
- func InsertBatch(ctx context.Context, ts *[]Table) (rowsAffected int64, lastInsertId int64, err error)
- func ListenField(lf func(filedInfo *fieldInfo))
- func NewPage() *page
- func NewSqlInfo(ctx context.Context, statement string, param ...any) rawTableSqlInfo
- func PrefixLower(s string) string
- func PrefixUpper(s string) string
- func Save(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
- func Select[T Table](ctx context.Context, columns ...string) *sqlInfo[T]
- func SqlScript[T Table](ctx context.Context, statement string, param ...any) *sqlInfo[T]
- func StringInIndex(s string, slice []string) int
- func StringInSlice(s string, slice []string) bool
- func Transaction(ctx context.Context, call func(ctx context.Context) error) error
- func UpdateByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
- func UpdateNotIgnoredEveryColumnByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
- func WithConf(ctx context.Context, conf confString) context.Context
- func WithTX(ctx context.Context, tx *sql.Tx) context.Context
- func WithTxOptions(ctx context.Context, txo *sql.TxOptions) context.Context
- func WriteStruct(ctx context.Context, info *structInfo) error
- func WriteStructTo(ctx context.Context, info *structInfo, absDir string) error
- type CodeFactory
- type Config
- type Table
- type TableSlice
Constants ¶
This section is empty.
Variables ¶
var ( FuncLog = defaultLog FuncSQLLog = defaultSqlLog FuncGenId = genId )
Functions ¶
func AddDataTypeFunc ¶
func AddDataTypeFunc(dataType string, fun dataTypeFun)
AddDataTypeFunc 添加一个自定义类型转换函数,优先级高于 columnTypeParse 函数内所列举的类型
func Convert ¶ added in v0.0.6
Convert 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)
func ConvertColIndex ¶ added in v0.0.6
ConvertColIndex 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)
func ConvertColName ¶ added in v0.0.6
ConvertColName 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)
func ConvertToStringSlice ¶
ConvertToStringSlice 将任意数据类型转换成string slice
func DeleteByPk ¶
DeleteByPk 仅根据主键删除
func GetContextDBConn ¶
GetContextDBConn 从上下文中获取链接
func GetContextTxConn ¶
GetContextTxConn 从上下文中获取事务
func GetContextTxOptions ¶
GetContextTxOptions 从上下文中获取配置事务参数
func Insert ¶
Insert 属性默认值遵循go语言基本类型的默认值 int=0;string="";time="0000-01-01 00:00:00" ...等 新增时的非自增的主键由调用方处理,可使用主键生成工具类(tcode.FuncGenId)生成
func InsertBatch ¶
func InsertBatch(ctx context.Context, ts *[]Table) (rowsAffected int64, lastInsertId int64, err error)
InsertBatch 批量新增
func ListenField ¶
func ListenField(lf func(filedInfo *fieldInfo))
ListenField 监听所有处理后的字段,并可直接根据需求修改信息
func NewSqlInfo ¶
func Transaction ¶
func UpdateByPk ¶
UpdateByPk 忽略每一个空列 仅根据主键更新
func UpdateNotIgnoredEveryColumnByPk ¶
func UpdateNotIgnoredEveryColumnByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)
UpdateNotIgnoredEveryColumnByPk 不忽略任何一列 仅根据主键更新
func WriteStruct ¶
WriteStruct 将*StructInfo信息通过模板codeTemplateText解析导出至defaultAbsDir路径
Types ¶
type CodeFactory ¶
type CodeFactory interface { ToStructInfo(ctx context.Context, fullyTableName, tableComment string) (*structInfo, error) ToAllStructInfo(ctx context.Context) ([]*structInfo, error) ToAllStructInfoOtherDb(ctx context.Context, dbName string) ([]*structInfo, error) // contains filtered or unexported methods }
func New ¶
func New(cfg *Config) (actuators confString, codeConstructor CodeFactory, err error)
New 创建一个tcode
type Config ¶
type Config struct { Dsn string DriverName string Dialect string MaxOpenConns int MaxIdleConns int ConnMaxLifetimeSecond int DB *sql.DB DefaultTxOptions *sql.TxOptions PrimaryKeyColumnName string //用于统一主键列,所有表的主键列名称必须为此值,否则无法使用代码生成器 SkipDefaultTransaction bool //是否跳过默认(增,删,改)事务 PackageName string //代码生成器生产代码所使用的包名 DebugSQL bool //是否开启调试sql,会将参数值拼接好的完整sql打印至控制台,用户开发阶段调试复杂sql,可直接在sql控制台执行的sql }
type TableSlice ¶
type TableSlice[T Table] []T