database

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists            = errors.New("duplicated key")
	ErrForeignKeyConstrainError = errors.New("foreign key error")
	ErrNotFound                 = errors.New("not found")
)

Functions

func Ctx

func Ctx(ctx context.Context) (*sql.DB, error)

func MySQLLogger added in v0.0.2

func MySQLLogger(slowQueryThreshold time.Duration) func(context.Context, mysql.QueryInfo)

func New

func PostgresLogger added in v0.0.2

func PostgresLogger(slowQueryThreshold time.Duration) func(context.Context, postgres.QueryInfo)

func TranslateError

func TranslateError(err error) error

func WithContext

func WithContext(parent context.Context, db *sql.DB) (ctx context.Context)

Types

type Configuration

type Configuration struct {
	Driver string `description:"Database driver"`
	DSN    string `description:"Database connection string"`

	SlowQueryThreshold time.Duration `description:"Threshold for logging slow queries"`

	ConnMaxIdleTime time.Duration `description:"Maximum amount of time a connection may be idle before being closed"`
	ConnMaxLifetime time.Duration `description:"Maximum amount of time a connection may be reused"`
	MaxIdleConns    int           `description:"Maximum number connections in the idle connection pool"`
	MaxOpenConns    int           `description:"Maximum number of open connections to the database"`
}

func NewConfiguration

func NewConfiguration() *Configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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