gormdb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package gormdb provides the database-agnostic core for GORM integration.

It defines the generic DBClient wrapper, configuration options, transaction management, and monitoring hooks. This package is designed to be used in conjunction with a driver-specific implementation (e.g., gormpg for PostgreSQL, gormmysql for MySQL), which provides the specific dialector and connection logic.

This separation of concerns allows for easy extensibility to support multiple database drivers while reusing the core GORM interaction logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireAdvisoryLock

func AcquireAdvisoryLock(ctx context.Context, tx *gorm.DB, lockID int) error

AcquireAdvisoryLock acquires a PostgreSQL advisory lock using the provided transaction.

func NewDeleter

func NewDeleter[R any](db *DBClient) *deleter[R]

func NewTransactioner

func NewTransactioner(db *DBClient, log logger.Logger) *transactioner

func ReleaseAdvisoryLock

func ReleaseAdvisoryLock(ctx context.Context, tx *gorm.DB, lockID int) error

ReleaseAdvisoryLock releases a PostgreSQL advisory lock using the provided transaction.

Types

type DBClient

type DBClient struct {
	*gorm.DB
}

DBClient implements a sqldb.Client using gorm.

func Must

func Must(cli *DBClient, err error) *DBClient

Must ensures a DBClient is returned only when there is no error, else it panics.

func New

func New(dialector gorm.Dialector, m monitoring.Monitor, options ...Option) (*DBClient, error)

func (*DBClient) Close

func (cli *DBClient) Close() error

Close closes to connections with the database.

func (*DBClient) Database

func (cli *DBClient) Database() (*sql.DB, error)

Database allows to retrieve the sql.DB database handle.

func (*DBClient) Ping

func (cli *DBClient) Ping() error

Ping pings the database (helpful for healthchecking purposes).

func (*DBClient) PingContext

func (cli *DBClient) PingContext(ctx context.Context) error

PingContext pings the database with the given context (helpful for healthchecking purposes).

func (*DBClient) WithContext

func (cli *DBClient) WithContext(ctx context.Context) *gorm.DB

type MonitorOption

type MonitorOption func(c *monitorConfig)

func SlowQueriesThreshold

func SlowQueriesThreshold(slowQueryThreshold time.Duration) MonitorOption

type Option

type Option func(*config) error

Option defines the contract for options applied to a gormdb.DBClient.

func WithDefaultTransaction

func WithDefaultTransaction(enabled bool) Option

func WithMonitorOpts

func WithMonitorOpts(options ...MonitorOption) Option

func WithNestedTransactions

func WithNestedTransactions(enabled bool) Option

func WithNowFunc

func WithNowFunc(f func() time.Time) Option

func WithSQLConnectionOptions

func WithSQLConnectionOptions(options ...sqldb.ConnectionOption) Option

func WithSingularTable

func WithSingularTable(enabled bool) Option

Directories

Path Synopsis
Package gormpg provides the PostgreSQL-specific implementation for the gormdb client.
Package gormpg provides the PostgreSQL-specific implementation for the gormdb client.

Jump to

Keyboard shortcuts

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