Documentation
¶
Index ¶
- Variables
- type PostgresDB
- func (p *PostgresDB) BeginTx(ctx context.Context, opts *sql.TxOptions) *gorm.DB
- func (p *PostgresDB) Close() error
- func (p *PostgresDB) GetStats() sql.DBStats
- func (p *PostgresDB) HealthCheck(ctx context.Context) error
- func (p *PostgresDB) Migrate(models ...interface{}) error
- func (p *PostgresDB) Ping(ctx context.Context) error
- func (p *PostgresDB) WithTransaction(ctx context.Context, fn func(*gorm.DB) error) error
- type Repository
- func (r *Repository) Create(ctx context.Context, model interface{}) error
- func (r *Repository) Delete(ctx context.Context, model interface{}) error
- func (r *Repository) GetByID(ctx context.Context, model interface{}, id interface{}) error
- func (r *Repository) Update(ctx context.Context, model interface{}) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = fmt.Errorf("record not found")
)
Custom errors
Functions ¶
This section is empty.
Types ¶
type PostgresDB ¶
PostgresDB wraps gorm.DB with additional functionality Note: Name kept as PostgresDB to avoid breaking changes in all services, but it now supports multiple database drivers.
func NewPostgresDB ¶
func NewPostgresDB(cfg *config.DatabaseConfig, log *logger.Logger) (*PostgresDB, error)
NewPostgresDB creates a new database connection (PostgreSQL or SQLite)
func (*PostgresDB) GetStats ¶
func (p *PostgresDB) GetStats() sql.DBStats
GetStats returns database connection statistics
func (*PostgresDB) HealthCheck ¶
func (p *PostgresDB) HealthCheck(ctx context.Context) error
HealthCheck performs a health check on the database
func (*PostgresDB) Migrate ¶
func (p *PostgresDB) Migrate(models ...interface{}) error
Migrate runs database migrations for the given models
func (*PostgresDB) Ping ¶
func (p *PostgresDB) Ping(ctx context.Context) error
Ping checks if the database connection is alive
func (*PostgresDB) WithTransaction ¶
WithTransaction executes a function within a database transaction
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository provides common database operations
func NewRepository ¶
func NewRepository(db *PostgresDB, 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{}) error
Delete deletes a record