Documentation
¶
Index ¶
- func ContainWithMasterOpt(opt []Option) bool
- func MaybeAddEqToWhere[T comparable](b *WhereBuilder, fieldEq T, column string, opt ...func(builder *WhereBuilder))
- func MaybeAddGtToWhere[T comparable](b *WhereBuilder, value T, column string, opt ...func(builder *WhereBuilder))
- func MaybeAddInToWhere[T any](b *WhereBuilder, fieldIn []T, column string, ...)
- func MaybeAddLikeToWhere(b *WhereBuilder, fieldLike string, column string, ...)
- func MaybeAddLteToWhere[T comparable](b *WhereBuilder, value T, column string, opt ...func(builder *WhereBuilder))
- func MaybeAddMultiLikeToWhere(b *WhereBuilder, fieldLikes []string, column string, ...)
- func RetryOnNotFound(fn func(opt ...Option) error, originalOpts []Option) error
- func WhereWithIndex(w *WhereBuilder)
- type Config
- type Option
- type Provider
- type WhereBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainWithMasterOpt ¶
func MaybeAddEqToWhere ¶
func MaybeAddEqToWhere[T comparable](b *WhereBuilder, fieldEq T, column string, opt ...func(builder *WhereBuilder))
func MaybeAddGtToWhere ¶
func MaybeAddGtToWhere[T comparable](b *WhereBuilder, value T, column string, opt ...func(builder *WhereBuilder))
func MaybeAddInToWhere ¶
func MaybeAddInToWhere[T any](b *WhereBuilder, fieldIn []T, column string, opt ...func(builder *WhereBuilder))
func MaybeAddLikeToWhere ¶
func MaybeAddLikeToWhere(b *WhereBuilder, fieldLike string, column string, opt ...func(builder *WhereBuilder))
MaybeAddLikeToWhere 模糊搜索,字符串为空时不添加。会对原字符串中的通配符进行转义,如 % 转义为 \%。
func MaybeAddLteToWhere ¶
func MaybeAddLteToWhere[T comparable](b *WhereBuilder, value T, column string, opt ...func(builder *WhereBuilder))
func MaybeAddMultiLikeToWhere ¶
func MaybeAddMultiLikeToWhere(b *WhereBuilder, fieldLikes []string, column string, opt ...func(builder *WhereBuilder))
MaybeAddMultiLikeToWhere 某个字段多个模糊搜索条件.
func RetryOnNotFound ¶
RetryOnNotFound 如果 fn 返回 gorm.ErrRecordNotFound 错误,则使用主库重试一次。 用于处理主从同步延迟导致的读取不到数据的情况,注意 gorm.DB.Find 不会返回 ErrRecordNotFound 错误。
func WhereWithIndex ¶
func WhereWithIndex(w *WhereBuilder)
Types ¶
type Config ¶
type Config struct {
Timeout time.Duration `yaml:"timeout"`
ReadTimeout time.Duration `yaml:"read_timeout"`
WriteTimeout time.Duration `yaml:"write_timeout"`
User string `yaml:"user"`
Password string `yaml:"password"`
Loc string `yaml:"loc"`
DBName string `yaml:"db_name"`
DBCharset string `yaml:"db_charset"`
DBHostname string `yaml:"db_hostname"`
DBPort string `yaml:"db_port"`
InterpolateParams bool `yaml:"interpolate_params"`
DSNParams url.Values `yaml:"dsn_params"`
WithReturning bool `yaml:"with_returning"`
}
type Option ¶
type Option func(option *option)
func WithSelectForUpdate ¶
func WithSelectForUpdate() Option
type Provider ¶
type Provider interface {
// NewSession 创建一个新的数据库会话
NewSession(ctx context.Context, opts ...Option) *gorm.DB
// Transaction 执行一个事务
Transaction(ctx context.Context, fc func(tx *gorm.DB) error, opts ...Option) error
}
func NewDBFromConfig ¶
NewDBFromConfig 从配置创建一个 db 实例
type WhereBuilder ¶
type WhereBuilder struct {
// contains filtered or unexported fields
}
func NewWhereBuilder ¶
func NewWhereBuilder() *WhereBuilder
func (*WhereBuilder) AddWhere ¶
func (b *WhereBuilder) AddWhere(expr clause.Expression)
func (*WhereBuilder) EqOrIn ¶
func (b *WhereBuilder) EqOrIn(column string, values ...any)
func (*WhereBuilder) WithIndex ¶
func (b *WhereBuilder) WithIndex()
Click to show internal directories.
Click to hide internal directories.