database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormLogger

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

Custom GORM logger that integrates with our logger

func NewGormLogger

func NewGormLogger(logger logger.Logger) *GormLogger

NewGormLogger creates a new GORM logger

func (*GormLogger) Error

func (gl *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error logs error messages

func (*GormLogger) Info

func (gl *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info logs info messages

func (*GormLogger) LogMode

func (gl *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

LogMode sets the log level

func (*GormLogger) Trace

func (gl *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace logs SQL queries

func (*GormLogger) Warn

func (gl *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn logs warning messages

type PostgresClient

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

PostgresClient provides PostgreSQL database operations

func NewPostgresClient

func NewPostgresClient(opts PostgresOptions) (*PostgresClient, error)

NewPostgresClient creates a new PostgreSQL client

func (*PostgresClient) Close

func (pc *PostgresClient) Close() error

Close closes the database connection

func (*PostgresClient) GetDB

func (pc *PostgresClient) GetDB() *gorm.DB

GetDB returns the GORM database instance

func (*PostgresClient) GetSQLDB

func (pc *PostgresClient) GetSQLDB() *sql.DB

GetSQLDB returns the underlying sql.DB instance

func (*PostgresClient) HealthCheck

func (pc *PostgresClient) HealthCheck() observability.HealthCheck

HealthCheck returns a health check for the database

func (*PostgresClient) Stats

func (pc *PostgresClient) Stats() sql.DBStats

Stats returns database connection statistics

func (*PostgresClient) Transaction

func (pc *PostgresClient) Transaction(ctx context.Context, fn func(*gorm.DB) error) error

Transaction executes a function within a database transaction

func (*PostgresClient) WithContext

func (pc *PostgresClient) WithContext(ctx context.Context) *gorm.DB

WithContext returns a new GORM DB instance with context

type PostgresOptions

type PostgresOptions struct {
	Config config.DatabaseConfig
	Logger logger.Logger
	Models []interface{} // Models to auto-migrate
}

PostgresOptions holds options for PostgreSQL client

type Repository

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

Repository provides common repository patterns

func NewRepository

func NewRepository(db *gorm.DB, logger logger.Logger) *Repository

NewRepository creates a new repository instance

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, model interface{}) error

Create creates a new record

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, model interface{}, id interface{}) error

Delete deletes a record

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, model interface{}, id interface{}) error

GetByID retrieves a record by ID

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, model interface{}) error

Update updates a record

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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