database

package
v0.0.0-...-123f038 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtContext

func ExtContext(ctx context.Context, db *sqlx.DB) sqlx.ExtContext

ExtContext 返回事务或连接池,供仓储在 Transaction 内使用。

func InTransaction

func InTransaction(ctx context.Context) bool

InTransaction 当前 context 是否处于数据库事务中。

func RawDB

func RawDB(d DB) *sql.DB

RawDB 返回标准库 *sql.DB(可选,用于第三方库)。

func Validate

func Validate(cfg config.DB) error

Types

type DB

type DB interface {
	Ping(ctx context.Context) error
	Transaction(ctx context.Context, fn func(ctx context.Context) error) error
	Close() error
	// SQLX 在 enabled 且 orm=sqlx 时返回连接池;Noop 或未启用时为 nil。
	SQLX() *sqlx.DB
}

DB 数据库抽象(默认 orm=sqlx)。

func NewNoop

func NewNoop() DB

func Open

func Open(cfg config.DB) (DB, error)

Jump to

Keyboard shortcuts

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