Documentation
¶
Index ¶
- Variables
- func Ctx(ctx context.Context, db *gorm.DB) context.Context
- func CtxNew(ctx context.Context) context.Context
- func DBAll[T DBModelID](ctx context.Context, cb func(context.Context, T) error, ops ...DBAllOption) error
- func ExecuteSQLFilesFromEmbed(ctx context.Context, fs embed.FS, dir string) error
- func For(ctx context.Context) *gorm.DB
- func GenID(ctx context.Context, name string) (int64, error)
- func Loader[T any](column string, key func(T) string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]
- func LoaderCtx[T any](column string, key func(context.Context, T) string, ...) *dataloadgen.Loader[string, T]
- func NewLoggerOp(logger logger.Interface) func(*gorm.Config)
- func Tx(ctx context.Context, f func(context.Context) error, opts ...*sql.TxOptions) error
- type Array
- type Config
- type DBAllConfig
- type DBAllOption
- type DBModelID
- type IDGen
- type Map
- type Model
- type Option
- type SQLExecutionHistory
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNilContext = errors.New("nil context")
View Source
var ErrNotFound = fmt.Errorf("not found")
Functions ¶
func DBAll ¶
func DBAll[T DBModelID](ctx context.Context, cb func(context.Context, T) error, ops ...DBAllOption) error
DBAll 按主键递增分页读取数据,并将结果分发给固定数量的工作协程并发执行回调。 通过透传 context 可以让外部取消信号和内部错误更快地停止后续分页与回调处理。
func ExecuteSQLFilesFromEmbed ¶
ExecuteSQLFilesFromEmbed reads SQL files from an embedded directory and executes them if not already executed. Uses a transaction to ensure atomicity of SQL execution and history recording.
func GenID ¶
Gen generates a new ID for the given name Uses Upsert to atomically increment the sequence number
func Loader ¶
func Loader[T any](column string, key func(T) string, options ...dataloadgen.Option) *dataloadgen.Loader[string, T]
Types ¶
type Config ¶
type DBAllConfig ¶
type DBAllOption ¶
type DBAllOption func(*DBAllConfig)
func WithDBAllConcurrency ¶
func WithDBAllConcurrency(concurrency int) DBAllOption
WithDBAllConcurrency 允许按需调整回调并发数,兼顾吞吐和下游处理能力。 channel 缓冲区会与并发数保持一致,避免生产速度远高于消费速度时积压过多内存。
func WithDBAllPageSize ¶
func WithDBAllPageSize(size int) DBAllOption
WithDBAllPageSize 允许按需调整分页大小,避免不同表规模下固定分页带来额外压力。
type Map ¶
type Map[K comparable, T any] map[K]T
type Model ¶
type SQLExecutionHistory ¶
Click to show internal directories.
Click to hide internal directories.