database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSetConnMaxLifetime    = time.Second * 60
	DefaultSetConnMaxIdleTime    = time.Second * 10
	DefaultSetMaxOpenConnections = 50
	DefaultSetMaxIdleConnections = 50
)

Default values for config.

Variables

View Source
var (
	ErrPanic          = errors.New("panic")
	ErrRollbackFailed = errors.New("rollback failed")
)

Functions

This section is empty.

Types

type Connector

type Connector interface {
	// DSN returns connection string.
	DSN() (string, error)
}

Connector for making connection.

type MetricCollector

type MetricCollector interface {
	// Collecting collects Metrics information for handlers.
	Collecting(method string, f func() error) func() error
}

MetricCollector is a helper for easy collecting metrics for every handler.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics contains general metrics for DAL methods.

func NewMetrics

func NewMetrics(reg *prometheus.Registry, namespace, subsystem string, methodsFrom any) (metric Metrics)

NewMetrics registers and returns common DAL metrics used by all services (namespace).

func (Metrics) Collecting

func (m Metrics) Collecting(method string, f func() error) func() error

Collecting implements MetricCollector.

type NoMetric

type NoMetric struct{}

NoMetric if you want to turn off metrics.

func (NoMetric) Collecting

func (n NoMetric) Collecting(_ string, f func() error) func() error

Collecting implements MetricCollector.

type SQL

type SQL struct {
	// contains filtered or unexported fields
}

SQL is a wrapper for sql database.

func NewSQL

func NewSQL(ctx context.Context, driver string, cfg SQLConfig, connector Connector) (*SQL, error)

NewSQL build and returns new SQL client.

func (*SQL) Close

func (db *SQL) Close() error

Close implements io.Closer.

func (*SQL) NoTx

func (db *SQL) NoTx(f func(*sqlx.DB) error) (err error)

NoTx provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - general metrics for DAL methods, - wrapping errors with DAL method name.

func (*SQL) NoTxContext

func (db *SQL) NoTxContext(ctx context.Context, f func(*sqlx.DB) error) (err error)

NoTxContext provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - general metrics for DAL methods, - wrapping errors with DAL method name, - tracing.

func (*SQL) Tx

func (db *SQL) Tx(ctx context.Context, opts *sql.TxOptions, f func(*sqlx.Tx) error) (err error)

Tx provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - general metrics for DAL methods, - wrapping errors with DAL method name, - transaction.

func (*SQL) UnderlyingDB

func (db *SQL) UnderlyingDB() *sql.DB

UnderlyingDB returns the underlying *sql.DB for use by metrics collectors and other components that need direct access to the connection pool stats.

type SQLConfig

type SQLConfig struct {
	ReturnErrs            []error
	Metrics               MetricCollector
	TracerProvider        trace.TracerProvider
	SetConnMaxLifetime    time.Duration
	SetConnMaxIdleTime    time.Duration
	SetMaxOpenConnections int
	SetMaxIdleConnections int
}

SQLConfig for set additional properties.

Directories

Path Synopsis
Package connectors contains implements for making connections to relation database.
Package connectors contains implements for making connections to relation database.
Package internal provide helpers for database.
Package internal provide helpers for database.

Jump to

Keyboard shortcuts

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