Documentation
¶
Overview ¶
Package postgres holds Postgres-specific error translation + small connection helpers (SQLSTATE → apierrors, advisory-lock primitives) shared by the gormdb and sqldb adapters.
Index ¶
- Constants
- func ErrorIs(err error, code string) bool
- func NewErrUnknown(err error) error
- type Model
- type Repo
- func (r *Repo) Commit() error
- func (r *Repo) CountApply(ctx context.Context, model any, q query.Query) (tx *gorm.DB)
- func (r *Repo) CountApplyWithTableName(ctx context.Context, model any, q query.Query, tableName string) (tx *gorm.DB)
- func (r *Repo) FMapper() map[string]string
- func (r *Repo) PatchApply(ctx context.Context, q query.Query, model any, toPatch map[string]any) (tx *gorm.DB)
- func (r *Repo) QueryApply(ctx context.Context, q query.Query, ops ...queryApplyOption) (tx *gorm.DB)
- func (r *Repo) QueryApplyWithTableName(ctx context.Context, q query.Query, tableName string, ops ...queryApplyOption) (tx *gorm.DB)
- func (r *Repo) Rollback() error
- type Timestamps
Constants ¶
View Source
const ErrDuplicateKey = "23505"
Variables ¶
This section is empty.
Functions ¶
func NewErrUnknown ¶
NewErrUnknown wraps a raw db/gorm error into an apierrors.Error. gorm.ErrRecordNotFound is translated to apierrors.NotFound so the REST/gRPC encoders surface it as 404 instead of 500 — every repo First()/Get() that didn't find a row would otherwise leak as a generic InternalError. Other errors stay InternalError; callers looking for SQLSTATE-specific translation should use ErrorIs first.
Types ¶
type Model ¶
type Model struct {
EID string `gorm:"column:id;type:uuid;default:uuid_generate_v4();primaryKey"`
Timestamps
}
func ModelFromResource ¶
type Repo ¶
func (*Repo) CountApply ¶
func (*Repo) CountApplyWithTableName ¶
func (*Repo) PatchApply ¶
func (*Repo) QueryApply ¶
func (*Repo) QueryApplyWithTableName ¶
type Timestamps ¶
type Timestamps struct {
ECreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime:true"`
EUpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime:true"`
EDeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp"`
}
func TimestampFromTimes ¶
func TimestampFromTimes(createdAt, updatedAt time.Time, deletedAt *time.Time) Timestamps
func (*Timestamps) CreatedAt ¶
func (t *Timestamps) CreatedAt() time.Time
func (*Timestamps) DeletedAt ¶
func (t *Timestamps) DeletedAt() *time.Time
func (*Timestamps) UpdatedAt ¶
func (t *Timestamps) UpdatedAt() time.Time
Click to show internal directories.
Click to hide internal directories.