databasebun

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AddToCtx

func AddToCtx(ctx context.Context, db bun.IDB) context.Context

func AddToCtxWithLane

func AddToCtxWithLane(ctx context.Context, db bun.IDB, name string) context.Context

func GetDBFromCtx

func GetDBFromCtx(ctx context.Context) bun.IDB

func GetDBFromCtxLane

func GetDBFromCtxLane(ctx context.Context, lane string) bun.IDB

func NewDB

func NewDB(conf config.Config, lf log.LoggerFactory) (*bun.DB, error)

NewDB creates a new database instance

func OnDBStop

func OnDBStop(ctx context.Context, db *bun.DB) error

func OpenSqlDB

func OpenSqlDB(conf config.Config, dbName string, lf log.LoggerFactory) (*sql.DB, error)

func RunInTx

func RunInTx(ctx context.Context, fn func(ctx context.Context) error) error

func RunInTxWithOpts

func RunInTxWithOpts(ctx context.Context, opts *sql.TxOptions, fn func(ctx context.Context) error) error

func WithLane

func WithLane(ctx context.Context, lane string) context.Context

WithLane adds a lane-specific DB to the context. It retrieves the current DB from the context and adds a new entry with the lane name as part of the key. This allows for multiple lanes to have their own DB instances in the same context, which can be useful for handling different database connections or transactions. Calls to GetDBFromCtx on the returned context will use the lane specific DB instead of the default one. If name is empty, then the original context is returned.

func WrapWithBun

func WrapWithBun(conf config.Config, slqDB *sql.DB) *bun.DB

Types

type BunLogger

type BunLogger struct{}

func (*BunLogger) AfterQuery

func (l *BunLogger) AfterQuery(ctx context.Context, event *bun.QueryEvent)

func (*BunLogger) BeforeQuery

func (l *BunLogger) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context

type Tx

type Tx struct {
	bun.Tx
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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