Versions in this module Expand all Collapse all v1 v1.2.0 Feb 21, 2026 v1.1.0 Feb 20, 2026 Changes in this version + var ErrAccountLocked = errors.New("account locked") + var ErrBackupFailed = errors.New("backup operation failed") + var ErrCheckConstraintViolation = errors.New("check constraint violation") + var ErrColumnNotFound = errors.New("column not found") + var ErrConfigurationError = errors.New("database configuration error") + var ErrConnectionFailed = errors.New("database connection failed") + var ErrConnectionLost = errors.New("connection lost") + var ErrConstraintViolation = errors.New("constraint violation") + var ErrCursorNotFound = errors.New("cursor not found") + var ErrDataTooLong = errors.New("data too long for column") + var ErrDatabaseNotFound = errors.New("database not found") + var ErrDeadlock = errors.New("deadlock detected") + var ErrDiskFull = errors.New("disk full") + var ErrDivisionByZero = errors.New("division by zero") + var ErrDuplicateKey = errors.New("duplicate key violation") + var ErrForeignKey = errors.New("foreign key violation") + var ErrFunctionNotFound = errors.New("function not found") + var ErrIdleInTransaction = errors.New("idle in transaction timeout") + var ErrIndexCorruption = errors.New("index corruption detected") + var ErrIndexNotFound = errors.New("index not found") + var ErrInsufficientPrivileges = errors.New("insufficient privileges") + var ErrInternalError = errors.New("internal database error") + var ErrInvalidCursor = errors.New("invalid cursor") + var ErrInvalidData = errors.New("invalid data") + var ErrInvalidDataType = errors.New("invalid data type") + var ErrInvalidJSON = errors.New("invalid JSON data") + var ErrInvalidPassword = errors.New("invalid password") + var ErrInvalidQuery = errors.New("invalid query") + var ErrLockTimeout = errors.New("lock acquisition timeout") + var ErrMigrationFailed = errors.New("migration failed") + var ErrNotNullViolation = errors.New("not null constraint violation") + var ErrNumericOverflow = errors.New("numeric value overflow") + var ErrPermissionDenied = errors.New("permission denied") + var ErrProtocolViolation = errors.New("protocol violation") + var ErrQueryTimeout = errors.New("query timeout exceeded") + var ErrRecordNotFound = errors.New("record not found") + var ErrRestoreFailed = errors.New("restore operation failed") + var ErrSchemaNotFound = errors.New("schema not found") + var ErrSchemaValidation = errors.New("schema validation failed") + var ErrSequenceNotFound = errors.New("sequence not found") + var ErrSerializationFailure = errors.New("serialization failure") + var ErrStatementTimeout = errors.New("statement timeout") + var ErrSystemError = errors.New("system error") + var ErrTableNotFound = errors.New("table not found") + var ErrTooManyConnections = errors.New("too many connections") + var ErrTransactionFailed = errors.New("transaction failed") + var ErrTriggerNotFound = errors.New("trigger not found") + var ErrUnsupportedOperation = errors.New("unsupported operation") + var ErrViewNotFound = errors.New("view not found") + var FXModule = fx.Module("postgres", ...) + func RegisterPostgresLifecycle(params PostgresLifeCycleParams) + type Client interface + Count func(ctx context.Context, model interface{}, count *int64, ...) error + Create func(ctx context.Context, value interface{}) error + DB func() *gorm.DB + Delete func(ctx context.Context, value interface{}, conditions ...interface{}) (int64, error) + Exec func(ctx context.Context, sql string, values ...interface{}) (int64, error) + Find func(ctx context.Context, dest interface{}, conditions ...interface{}) error + First func(ctx context.Context, dest interface{}, conditions ...interface{}) error + GetErrorCategory func(err error) ErrorCategory + GracefulShutdown func() error + IsCritical func(err error) bool + IsRetryable func(err error) bool + IsTemporary func(err error) bool + Query func(ctx context.Context) QueryBuilder + Save func(ctx context.Context, value interface{}) error + Transaction func(ctx context.Context, fn func(tx Client) error) error + TranslateError func(err error) error + Update func(ctx context.Context, model interface{}, attrs interface{}) (int64, error) + UpdateColumn func(ctx context.Context, model interface{}, columnName string, value interface{}) (int64, error) + UpdateColumns func(ctx context.Context, model interface{}, columnValues map[string]interface{}) (int64, error) + UpdateWhere func(ctx context.Context, model interface{}, attrs interface{}, condition string, ...) (int64, error) + func ProvideClient(pg *Postgres) Client + type Config struct + Connection Connection + ConnectionDetails ConnectionDetails + type Connection struct + DbName string + Host string + Password string + Port string + SSLMode string + User string + type ConnectionDetails struct + ConnMaxLifetime time.Duration + MaxIdleConns int + MaxOpenConns int + type ErrorCategory int + const CategoryConnection + const CategoryConstraint + const CategoryData + const CategoryOperation + const CategoryPermission + const CategoryQuery + const CategoryResource + const CategorySchema + const CategorySystem + const CategoryTransaction + const CategoryUnknown + type Logger interface + ErrorWithContext func(ctx context.Context, msg string, err error, fields ...map[string]interface{}) + InfoWithContext func(ctx context.Context, msg string, err error, fields ...map[string]interface{}) + WarnWithContext func(ctx context.Context, msg string, err error, fields ...map[string]interface{}) + type Migration struct + Direction MigrationDirection + ID string + Name string + SQL string + Type MigrationType + type MigrationDirection string + const DownMigration + const UpMigration + type MigrationHistoryRecord struct + Duration int64 + ErrorMessage string + ExecutedAt time.Time + ExecutedBy string + ID string + Name string + Status string + Type string + type MigrationType string + const DataType + const SchemaType + type Postgres struct + func NewPostgres(cfg Config) (*Postgres, error) + func NewPostgresClientWithDI(params PostgresParams) (*Postgres, error) + func (p *Postgres) AutoMigrate(models ...interface{}) error + func (p *Postgres) Count(ctx context.Context, model interface{}, count *int64, ...) error + func (p *Postgres) Create(ctx context.Context, value interface{}) error + func (p *Postgres) CreateMigration(migrationsDir, name string, migrationType MigrationType) (string, error) + func (p *Postgres) DB() *gorm.DB + func (p *Postgres) Delete(ctx context.Context, value interface{}, conditions ...interface{}) (int64, error) + func (p *Postgres) Exec(ctx context.Context, sql string, values ...interface{}) (int64, error) + func (p *Postgres) Find(ctx context.Context, dest interface{}, conditions ...interface{}) error + func (p *Postgres) First(ctx context.Context, dest interface{}, conditions ...interface{}) error + func (p *Postgres) GetErrorCategory(err error) ErrorCategory + func (p *Postgres) GetMigrationStatus(ctx context.Context, migrationsDir string) ([]map[string]interface{}, error) + func (p *Postgres) GracefulShutdown() error + func (p *Postgres) IsCritical(err error) bool + func (p *Postgres) IsRetryable(err error) bool + func (p *Postgres) IsTemporary(err error) bool + func (p *Postgres) MigrateDown(ctx context.Context, migrationsDir string) error + func (p *Postgres) MigrateUp(ctx context.Context, migrationsDir string) error + func (p *Postgres) MonitorConnection(ctx context.Context) + func (p *Postgres) Query(ctx context.Context) QueryBuilder + func (p *Postgres) RetryConnection(ctx context.Context) + func (p *Postgres) Save(ctx context.Context, value interface{}) error + func (p *Postgres) Transaction(ctx context.Context, fn func(tx Client) error) error + func (p *Postgres) TranslateError(err error) error + func (p *Postgres) Update(ctx context.Context, model interface{}, attrs interface{}) (int64, error) + func (p *Postgres) UpdateColumn(ctx context.Context, model interface{}, columnName string, value interface{}) (int64, error) + func (p *Postgres) UpdateColumns(ctx context.Context, model interface{}, columnValues map[string]interface{}) (int64, error) + func (p *Postgres) UpdateWhere(ctx context.Context, model interface{}, attrs interface{}, condition string, ...) (int64, error) + func (p *Postgres) WithLogger(logger Logger) *Postgres + func (p *Postgres) WithObserver(observer observability.Observer) *Postgres + type PostgresLifeCycleParams struct + Lifecycle fx.Lifecycle + Postgres *Postgres + type PostgresParams struct + Config Config + Logger Logger + Observer observability.Observer + type QueryBuilder interface + Clauses func(conds ...interface{}) QueryBuilder + Count func(count *int64) error + Create func(value interface{}) (int64, error) + CreateInBatches func(value interface{}, batchSize int) (int64, error) + Delete func(value interface{}) (int64, error) + Distinct func(args ...interface{}) QueryBuilder + Done func() + Find func(dest interface{}) error + First func(dest interface{}) error + FirstOrCreate func(dest interface{}, conds ...interface{}) error + FirstOrInit func(dest interface{}, conds ...interface{}) error + ForKeyShare func() QueryBuilder + ForNoKeyUpdate func() QueryBuilder + ForShare func() QueryBuilder + ForShareSkipLocked func() QueryBuilder + ForUpdate func() QueryBuilder + ForUpdateNoWait func() QueryBuilder + ForUpdateSkipLocked func() QueryBuilder + Group func(query string) QueryBuilder + Having func(query interface{}, args ...interface{}) QueryBuilder + Joins func(query string, args ...interface{}) QueryBuilder + Last func(dest interface{}) error + LeftJoin func(query string, args ...interface{}) QueryBuilder + Limit func(limit int) QueryBuilder + Model func(value interface{}) QueryBuilder + Not func(query interface{}, args ...interface{}) QueryBuilder + Offset func(offset int) QueryBuilder + OnConflict func(onConflict interface{}) QueryBuilder + Or func(query interface{}, args ...interface{}) QueryBuilder + Order func(value interface{}) QueryBuilder + Pluck func(column string, dest interface{}) (int64, error) + Preload func(query string, args ...interface{}) QueryBuilder + Raw func(sql string, values ...interface{}) QueryBuilder + Returning func(columns ...string) QueryBuilder + RightJoin func(query string, args ...interface{}) QueryBuilder + Scan func(dest interface{}) error + Scopes func(funcs ...func(*gorm.DB) *gorm.DB) QueryBuilder + Select func(query interface{}, args ...interface{}) QueryBuilder + Table func(name string) QueryBuilder + ToSubquery func() *gorm.DB + Unscoped func() QueryBuilder + Updates func(values interface{}) (int64, error) + Where func(query interface{}, args ...interface{}) QueryBuilder + type RowScanner interface + Scan func(dest ...interface{}) error + type RowsScanner interface + Close func() error + Err func() error + Next func() bool + Scan func(dest ...interface{}) error