postgres

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 19 Imported by: 0

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

View Source
const ErrDuplicateKey = "23505"

Variables

This section is empty.

Functions

func ErrorIs

func ErrorIs(err error, code string) bool

func NewErrUnknown

func NewErrUnknown(err error) error

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

func ModelFromResource(r resource.Resource) Model

func (*Model) ID

func (d *Model) ID() string

func (*Model) LID

func (d *Model) LID() string

type Repo

type Repo struct {
	DB *gormdb.DBClient
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo(db *gormdb.DBClient, fMapper map[string]string) (*Repo, error)

func (*Repo) Commit

func (r *Repo) Commit() error

func (*Repo) CountApply

func (r *Repo) CountApply(ctx context.Context, model any, q query.Query) (tx *gorm.DB)

func (*Repo) CountApplyWithTableName

func (r *Repo) CountApplyWithTableName(ctx context.Context, model any, q query.Query, tableName string) (tx *gorm.DB)

func (*Repo) FMapper

func (r *Repo) FMapper() map[string]string

func (*Repo) PatchApply

func (r *Repo) PatchApply(ctx context.Context, q query.Query, model any, toPatch map[string]any) (tx *gorm.DB)

func (*Repo) QueryApply

func (r *Repo) QueryApply(ctx context.Context, q query.Query, ops ...queryApplyOption) (tx *gorm.DB)

func (*Repo) QueryApplyWithTableName

func (r *Repo) QueryApplyWithTableName(ctx context.Context, q query.Query, tableName string, ops ...queryApplyOption) (tx *gorm.DB)

func (*Repo) Rollback

func (r *Repo) Rollback() error

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

Jump to

Keyboard shortcuts

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