sql

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoLevel    = "info"
	WarnLevel    = "warn"
	WarningLevel = "warning"
	ErrorLevel   = "error"
	SilentLevel  = "silent"
)
View Source
const (
	JoinTypeInner = "INNER"
	JoinTypeLeft  = "LEFT"
	JoinTypeRight = "RIGHT"
)

Variables

View Source
var (
	PercentSignUTF8, _ = utf8.DecodeRuneInString("%")
	UnderscoreUTF8, _  = utf8.DecodeRuneInString("_")
	EscapeCharUTF8, _  = utf8.DecodeRuneInString(`\`)
)
View Source
var (
	DBKeyError     = errors.EC_SQL_DB_KEY_ERROR
	DefaultDBError = errors.EC_SQL_DEFAULT_DB_ERROR
)
View Source
var SilentLogger = NewLogger(&LogConfig{
	Level:         SilentLevel,
	SlowThreshold: defaultSlowThreshold,
})

Functions

func EscapeLikeString

func EscapeLikeString(s string) string

func FuzzySearch

func FuzzySearch(s string) string

func NewFieldMetaMapping

func NewFieldMetaMapping[T CTable](ml schema.Tabler, fm T) *T

func NewGlobalFieldMetaMapping

func NewGlobalFieldMetaMapping[T CTable](ml schema.Tabler, fm T, tAs ...string) *T

func NewLogger

func NewLogger(cfg *LogConfig) logger.Interface

func PrefixSearch

func PrefixSearch(s string) string

func SetDefaultDB

func SetDefaultDB(fn DefaultDB)

func SuffixSearch

func SuffixSearch(s string) string

Types

type BaseOpr

type BaseOpr struct {
	// contains filtered or unexported fields
}

func NewBaseOpr

func NewBaseOpr(db *gorm.DB) *BaseOpr

func (*BaseOpr) DB

func (b *BaseOpr) DB(ctx context.Context) *gorm.DB

func (*BaseOpr) Distinct

func (b *BaseOpr) Distinct(distinct ...field.Expr) func(*gorm.DB) *gorm.DB

func (*BaseOpr) Group

func (b *BaseOpr) Group(group ...field.Expr) func(*gorm.DB) *gorm.DB

func (*BaseOpr) Having

func (b *BaseOpr) Having(having ...any) func(*gorm.DB) *gorm.DB

func (*BaseOpr) Join

func (b *BaseOpr) Join(table string, field field.Expr) func(db *gorm.DB) *gorm.DB

func (*BaseOpr) LeftJoin

func (b *BaseOpr) LeftJoin(table string, field field.Expr) func(db *gorm.DB) *gorm.DB

func (*BaseOpr) NewDB

func (b *BaseOpr) NewDB() *gorm.DB

func (*BaseOpr) Opr

func (b *BaseOpr) Opr(ctx context.Context) *BaseOpr

func (*BaseOpr) Or

func (b *BaseOpr) Or(exprs ...field.Expr) func(db *gorm.DB) *gorm.DB

func (*BaseOpr) Order

func (b *BaseOpr) Order(orders ...field.Expr) func(*gorm.DB) *gorm.DB

func (*BaseOpr) Page

func (b *BaseOpr) Page(page, pageSize int) func(*gorm.DB) *gorm.DB

func (*BaseOpr) RightJoin

func (b *BaseOpr) RightJoin(table string, field field.Expr) func(db *gorm.DB) *gorm.DB

func (*BaseOpr) Select

func (b *BaseOpr) Select(selects ...field.Expr) func(*gorm.DB) *gorm.DB

func (*BaseOpr) SilentDB

func (b *BaseOpr) SilentDB(ctx context.Context) *gorm.DB

func (*BaseOpr) Where

func (b *BaseOpr) Where(where ...field.Expr) func(*gorm.DB) *gorm.DB

type CTable

type CTable interface {
	TableName() string
	Table() string
	As() string
}

func NewCTable

func NewCTable(tableName string, ass ...string) CTable

type Corm

type Corm interface {
	Where(where ...field.Expr) func(*gorm.DB) *gorm.DB
	Or(exprs ...field.Expr) func(db *gorm.DB) *gorm.DB
	Select(selects ...field.Expr) func(*gorm.DB) *gorm.DB
	Page(page, pageSize int) func(*gorm.DB) *gorm.DB
	Order(orders ...field.Expr) func(*gorm.DB) *gorm.DB
	Join(table string, field field.Expr) func(*gorm.DB) *gorm.DB
	LeftJoin(table string, field field.Expr) func(*gorm.DB) *gorm.DB
	RightJoin(table string, field field.Expr) func(*gorm.DB) *gorm.DB
	Distinct(distinct ...field.Expr) func(*gorm.DB) *gorm.DB
	Group(group ...field.Expr) func(*gorm.DB) *gorm.DB
	Having(having ...any) func(*gorm.DB) *gorm.DB
}

type DefaultDB

type DefaultDB func() *gorm.DB

type LogConfig

type LogConfig struct {
	Level         string        `json:"level,omitempty"`
	SlowThreshold time.Duration `json:"slow_threshold,omitempty"`
}

type SqlTX

type SqlTX struct{}

func (SqlTX) Execute

func (m SqlTX) Execute(ctx context.Context, fun func(ctx context.Context) error) error

type Transaction

type Transaction interface {
	Execute(ctx context.Context, fn func(context.Context) error) error
}

func NewSqlTX

func NewSqlTX() Transaction

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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