db

package
v1.0.4-snapshot Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalDB *gorm.DB

GlobalDB 全局数据库实例

Functions

func CloseDB

func CloseDB(ctx context.Context) error

CloseDB 关闭GORM数据库连接(带上下文超时)

func InitMysql

func InitMysql(ctx context.Context)

InitMysql 初始化数据库

Types

type AppConfigLoadedEventListener

type AppConfigLoadedEventListener struct{}

func (*AppConfigLoadedEventListener) GetOrder

func (ace *AppConfigLoadedEventListener) GetOrder() int

func (*AppConfigLoadedEventListener) OnApplicationEvent

func (ace *AppConfigLoadedEventListener) OnApplicationEvent(ctx context.Context, event *listener.AppConfigLoadedEvent)

type AppShutDownEventListener

type AppShutDownEventListener struct{}

func (*AppShutDownEventListener) GetOrder

func (l *AppShutDownEventListener) GetOrder() int

func (*AppShutDownEventListener) OnApplicationEvent

func (l *AppShutDownEventListener) OnApplicationEvent(ctx context.Context, event *listener.AppShutdownEvent)

type BaseDao

type BaseDao[T any] struct {
}

func NewBaseDao

func NewBaseDao[T any]() *BaseDao[T]

func (*BaseDao[T]) Delete

func (b *BaseDao[T]) Delete(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) error

Delete 根据条件删除记录

func (*BaseDao[T]) DeleteById

func (b *BaseDao[T]) DeleteById(ctx context.Context, id any, opts ...gplus.OptionFunc) error

DeleteById 根据 ID 删除记录

func (*BaseDao[T]) DeleteByIds

func (b *BaseDao[T]) DeleteByIds(ctx context.Context, ids any, opts ...gplus.OptionFunc) error

DeleteByIds 根据 ID 批量删除记录

func (*BaseDao[T]) Exists

func (b *BaseDao[T]) Exists(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (bool, error)

Exists 根据条件判断记录是否存在

func (*BaseDao[T]) Insert

func (b *BaseDao[T]) Insert(ctx context.Context, entity *T, opts ...gplus.OptionFunc) error

Insert 插入一条记录

func (*BaseDao[T]) InsertBatch

func (b *BaseDao[T]) InsertBatch(ctx context.Context, entities []*T, opts ...gplus.OptionFunc) error

InsertBatch 批量插入多条记录

func (*BaseDao[T]) InsertBatchSize

func (b *BaseDao[T]) InsertBatchSize(
	ctx context.Context, entities []*T, batchSize int, opts ...gplus.OptionFunc) error

InsertBatchSize 批量插入多条记录

func (*BaseDao[T]) NewQueryCond

func (b *BaseDao[T]) NewQueryCond() (*gplus.QueryCond[T], *T)

NewQueryCond 创建查询条件

func (*BaseDao[T]) SelectById

func (b *BaseDao[T]) SelectById(ctx context.Context, id any, opts ...gplus.OptionFunc) (*T, error)

SelectById 根据 ID 查询单条记录

func (*BaseDao[T]) SelectByIds

func (b *BaseDao[T]) SelectByIds(ctx context.Context, ids any, opts ...gplus.OptionFunc) ([]*T, error)

SelectByIds 根据 ID 查询多条记录

func (*BaseDao[T]) SelectCount

func (b *BaseDao[T]) SelectCount(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (int64, error)

SelectCount 根据条件查询记录数量

func (*BaseDao[T]) SelectList

func (b *BaseDao[T]) SelectList(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) ([]*T, error)

SelectList 根据条件查询多条记录

func (*BaseDao[T]) SelectOne

func (b *BaseDao[T]) SelectOne(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (*T, error)

SelectOne 根据条件查询单条记录

func (*BaseDao[T]) SelectPage

func (b *BaseDao[T]) SelectPage(
	ctx context.Context, page *gplus.Page[T], q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (
	*gplus.Page[T], error)

SelectPage 根据条件分页查询记录

func (*BaseDao[T]) Update

func (b *BaseDao[T]) Update(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) error

Update 根据 Map 更新

func (*BaseDao[T]) UpdateById

func (b *BaseDao[T]) UpdateById(ctx context.Context, entity *T, opts ...gplus.OptionFunc) error

UpdateById 根据 ID 更新,默认零值不更新

func (*BaseDao[T]) UpdateZeroById

func (b *BaseDao[T]) UpdateZeroById(ctx context.Context, entity *T, opts ...gplus.OptionFunc) error

UpdateZeroById 根据 ID 零值更新

type BaseDaoGeneric

type BaseDaoGeneric[T any, R any] struct {
	*BaseDao[T]
}

func NewBaseDaoGeneric

func NewBaseDaoGeneric[T any, R any]() *BaseDaoGeneric[T, R]

func (*BaseDaoGeneric[T, R]) SelectGeneric

func (b *BaseDaoGeneric[T, R]) SelectGeneric(ctx context.Context, q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (
	R, error)

SelectGeneric 根据传入的泛型封装记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

func (*BaseDaoGeneric[T, R]) SelectPageGeneric

func (b *BaseDaoGeneric[T, R]) SelectPageGeneric(
	ctx context.Context, page *gplus.Page[R], q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (
	*gplus.Page[R], error)

SelectPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

type BaseDaoStreamingGeneric

type BaseDaoStreamingGeneric[T any, R any, V gplus.Comparable] struct {
	*BaseDao[T]
}

func NewBaseDaoStreamingGeneric

func NewBaseDaoStreamingGeneric[T any, R any, V gplus.Comparable]() *BaseDaoStreamingGeneric[T, R, V]

func (*BaseDaoStreamingGeneric[T, R, V]) SelectStreamingPageGeneric

func (b *BaseDaoStreamingGeneric[T, R, V]) SelectStreamingPageGeneric(
	ctx context.Context, page *gplus.StreamingPage[R, V], q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (
	*gplus.StreamingPage[R, V], error)

SelectStreamingPageGeneric 根据传入的泛型封装分页记录 第一个泛型代表数据库表实体 第二个泛型代表返回记录实体

type BaseDaoWithComparable

type BaseDaoWithComparable[T any, V gplus.Comparable] struct {
	*BaseDao[T]
}

func NewBaseDaoWithComparable

func NewBaseDaoWithComparable[T any, V gplus.Comparable]() *BaseDaoWithComparable[T, V]

func (*BaseDaoWithComparable[T, V]) SelectStreamingPage

func (b *BaseDaoWithComparable[T, V]) SelectStreamingPage(
	ctx context.Context, page *gplus.StreamingPage[T, V], q *gplus.QueryCond[T], opts ...gplus.OptionFunc) (
	*gplus.StreamingPage[T, V], error)

SelectStreamingPage 根据条件分页查询记录

type GormLogger

type GormLogger struct {
	LogLevel      logger.LogLevel // GORM 日志级别
	SlowThreshold time.Duration   // 慢查询阈值
}

GormLogger 实现 GORM 的 logger.Interface 接口

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode 设置当前的logger level

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Jump to

Keyboard shortcuts

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