tcode

package module
v0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FuncLog    = defaultLog
	FuncSQLLog = defaultLog
	FuncGenId  = genId
)

Functions

func AddDataTypeFunc

func AddDataTypeFunc(dataType string, fun dataTypeFun)

AddDataTypeFunc 添加一个自定义类型转换函数,优先级高于 columnTypeParse 函数内所列举的类型

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 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 NewSqlInfo

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

func PrefixLower

func PrefixLower(s string) string

PrefixLower 首字母小写

func PrefixUpper

func PrefixUpper(s string) string

PrefixUpper 首字母大写

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 //代码生成器生产代码所使用的包名
}

type Page

type Page struct {
	TotalCount  int `json:"totalCount"`
	TotalPage   int `json:"totalPage"`
	CurrentPage int `json:"currentPage"`
	NextPage    int `json:"nextPage"`
	PageSize    int `json:"pageSize"`
}

func NewPage

func NewPage() *Page

type Table

type Table interface {
	TableName() string
	RawColumnContainer(columns ...string) []interface{}
	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