tcode

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Convert(r *rawTable, ptr any) (err error)

Convert 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)

func ConvertColIndex added in v0.0.6

func ConvertColIndex(r *rawTable, colIndex int, ptr any) (err error)

ConvertColIndex 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)

func ConvertColName added in v0.0.6

func ConvertColName(r *rawTable, colName string, ptr any) (err error)

ConvertColName 转换为结构体或切片 可转换的类型(*struct ,*[]struct, *[]*struct, *[]基本类型, *基本类型)

func ConvertToString

func ConvertToString(val any) string

ConvertToString 将任意数据类型转换成string

func ConvertToStringSlice

func ConvertToStringSlice(val any) []string

ConvertToStringSlice 将任意数据类型转换成string slice

func DeleteByPk

func DeleteByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)

DeleteByPk 仅根据主键删除

func Exist added in v0.0.6

func Exist(ctx context.Context, t Table) (bool, error)

func GetContextDBConn

func GetContextDBConn(ctx context.Context) *sql.DB

GetContextDBConn 从上下文中获取链接

func GetContextTxConn

func GetContextTxConn(ctx context.Context) *sql.Tx

GetContextTxConn 从上下文中获取事务

func GetContextTxOptions

func GetContextTxOptions(ctx context.Context) *sql.TxOptions

GetContextTxOptions 从上下文中获取配置事务参数

func GetPkColumnName

func GetPkColumnName(ctx context.Context) string

GetPkColumnName 获取表的主键列名

func Hump

func Hump(column string) (filed string)

Hump 处理驼峰命名格式(字段名到属性名的转换)

func Insert

func Insert(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)

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 NewPage

func NewPage() *page

func NewSqlInfo

func NewSqlInfo(ctx context.Context, statement string, param ...any) rawTableSqlInfo

func PrefixLower

func PrefixLower(s string) string

PrefixLower 首字母小写

func PrefixUpper

func PrefixUpper(s string) string

PrefixUpper 首字母大写

func Save added in v0.0.6

func Save(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)

Save 保存: 新增或更新

func Select

func Select[T Table](ctx context.Context, columns ...string) *sqlInfo[T]

func SqlScript

func SqlScript[T Table](ctx context.Context, statement string, param ...any) *sqlInfo[T]

func StringInIndex

func StringInIndex(s string, slice []string) int

StringInIndex 字符串切片在切片中的下标

func StringInSlice

func StringInSlice(s string, slice []string) bool

StringInSlice 字符串切片中是否存在s

func Transaction

func Transaction(ctx context.Context, call func(ctx context.Context) error) error

func UpdateByPk

func UpdateByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)

UpdateByPk 忽略每一个空列 仅根据主键更新

func UpdateNotIgnoredEveryColumnByPk

func UpdateNotIgnoredEveryColumnByPk(ctx context.Context, t Table) (rowsAffected int64, lastInsertId int64, err error)

UpdateNotIgnoredEveryColumnByPk 不忽略任何一列 仅根据主键更新

func WithConf

func WithConf(ctx context.Context, conf confString) context.Context

func WithTX

func WithTX(ctx context.Context, tx *sql.Tx) context.Context

func WithTxOptions

func WithTxOptions(ctx context.Context, txo *sql.TxOptions) context.Context

func WriteStruct

func WriteStruct(ctx context.Context, info *structInfo) error

WriteStruct 将*StructInfo信息通过模板codeTemplateText解析导出至defaultAbsDir路径

func WriteStructTo

func WriteStructTo(ctx context.Context, info *structInfo, absDir string) error

WriteStructTo 将*StructInfo信息通过模板codeTemplateText解析导出至absDir路径

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 Table

type Table interface {
	TableName() string
	RawColumnContainer(columns ...string) []any
	NewTable() Table
	NewInstance() Table
	CopyFrom(src Table)
	Columns() []string
}

type TableSlice

type TableSlice[T Table] []T

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL