pg

package
v0.0.0-...-299e09f Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package pg ...

Index

Constants

This section is empty.

Variables

View Source
var ErrPGMissingPGConn = errors.New("postgres connection is nil")

Functions

func CreateExtensionQuery

func CreateExtensionQuery(extension SupportedExtension, schema string) (string, error)

func CreateSchemaQuery

func CreateSchemaQuery(name string) (string, error)

func CreateTypeFromEnumQuery

func CreateTypeFromEnumQuery(name string, vals ...fmt.Stringer) (string, error)

CreateTypeFromEnumQuery returns a query to create a type in a PostgresSQL DB only if the type does not already exist.

func ErrorIs

func ErrorIs(err error, code string) bool

func JsonbFromStringMaps

func JsonbFromStringMaps(m map[string]string) postgres.Jsonb

func NewDeleter

func NewDeleter[T any](repo *Repo, queryValFunc func(query.Query) error) *deleter[T]

func NewDestroyer

func NewDestroyer[R any](repo Repo) *destroyer[R]

func NewErrUnknown

func NewErrUnknown(err error) error

func NullInt32FromString

func NullInt32FromString(s string) sql.NullInt32

func NullSerialIDFromString

func NullSerialIDFromString(id string) *int32

func SerialIDFromString

func SerialIDFromString(id string) int32

func SpanErrSkipper

func SpanErrSkipper() errors.ErrSkipFunc

func TimePointerToPgTime

func TimePointerToPgTime(tp *time.Time) pgtype.Time

Types

type CustomModel

type CustomModel[T any] struct {
	ID_ T `gorm:"column:id;"`
	Timestamps
}

func CustomModelFromResource

func CustomModelFromResource(r resource.Resource) CustomModel[string]

func Int32CustomModelFromResource

func Int32CustomModelFromResource(r resource.Resource) CustomModel[int32]

func NewCustomModel

func NewCustomModel[T any](id T, createdAt, updatedAt time.Time, deletedAt *time.Time) CustomModel[T]

func (*CustomModel[T]) ID

func (d *CustomModel[T]) ID() T

type DeletedAtTime

type DeletedAtTime struct {
	gorm.DeletedAt
}

func (*DeletedAtTime) Scan

func (dat *DeletedAtTime) Scan(value any) error

func (DeletedAtTime) Value

func (dat DeletedAtTime) Value() (driver.Value, error)

type Err

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

func (Err) Error

func (e Err) Error() string

func (Err) Is

func (e Err) Is(err error) bool

func (Err) Unwrap

func (e Err) Unwrap() error

type FieldColumnMapper

type FieldColumnMapper map[fields.Name]string

func (FieldColumnMapper) Column

func (m FieldColumnMapper) Column(field fields.Name) string

type Hstore

type Hstore map[string]*string

func (*Hstore) Scan

func (h *Hstore) Scan(value interface{}) error

Scan scan value into Hstore

func (Hstore) Value

func (h Hstore) Value() (driver.Value, error)

Value get value of Hstore

type Jsonb

type Jsonb struct {
	json.RawMessage
}

Jsonb Postgresql's JSONB data type

func (*Jsonb) Scan

func (j *Jsonb) Scan(value interface{}) error

Scan scan value into Jsonb

func (Jsonb) Value

func (j Jsonb) Value() (driver.Value, error)

Value get value of Jsonb

type Model

type Model struct {
	ID_ string `gorm:"column:id;type:uuid;default:uuid_generate_v4();primaryKey"`
	Timestamps
}

func ModelFromResource

func ModelFromResource(r resource.Resource) Model

func NewModel

func NewModel(id string, createdAt, updatedAt time.Time, deletedAt *time.Time) Model

func (*Model) ID

func (d *Model) ID() string

func (*Model) LID

func (d *Model) LID() string

type NullTime

type NullTime struct {
	pq.NullTime
}

func NewNullTime

func NewNullTime(t *time.Time) NullTime

func (*NullTime) OrNil

func (nt *NullTime) OrNil() *time.Time

func (*NullTime) Scan

func (nt *NullTime) Scan(value any) error

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

type Point

type Point struct {
	PointX, PointY float64
}

func (*Point) Scan

func (p *Point) Scan(src interface{}) (err error)

func (Point) Value

func (p Point) Value() (driver.Value, error)

func (Point) X

func (p Point) X() float64

func (Point) Y

func (p Point) Y() float64

type Repo

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

func NewRepo

func NewRepo(db *gormcli.DBClient, fMapper map[fields.Name]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() FieldColumnMapper

func (*Repo) PatchApply

func (r *Repo) PatchApply(ctx context.Context, q query.Query, model any, toPatch map[fields.Name]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 SerialModel

type SerialModel struct {
	ID_ int `gorm:"primaryKey;autoIncrement=false;column:id;type:serial"`
	Timestamps
}

func NewSerialModel

func NewSerialModel(id int, createdAt, updatedAt time.Time, deletedAt *time.Time) SerialModel

func SerialModelFromResource

func SerialModelFromResource(r resource.Resource) SerialModel

func (*SerialModel) ID

func (d *SerialModel) ID() string

func (*SerialModel) LID

func (d *SerialModel) LID() string

type SerialModel32

type SerialModel32 struct {
	ID_ int32 `gorm:"primaryKey;column:id;type:serial"`
	Timestamps
}

func NewSerialModel32

func NewSerialModel32(id int32, createdAt, updatedAt time.Time, deletedAt *time.Time) SerialModel32

func SerialModel32FromResource

func SerialModel32FromResource(r resource.Resource) SerialModel32

func (*SerialModel32) ID

func (d *SerialModel32) ID() string

func (*SerialModel32) LID

func (d *SerialModel32) LID() string

type SupportedExtension

type SupportedExtension string

type Time

type Time struct {
	time.Time
}

func NewTime

func NewTime(t time.Time) Time

func (*Time) Scan

func (t *Time) Scan(value any) error

func (Time) Value

func (t Time) Value() (driver.Value, error)

type Timestamps

type Timestamps struct {
	CreatedAt_ Time          `gorm:"column:created_at;type:timestamp;autoCreateTime:true"`
	UpdatedAt_ Time          `gorm:"column:updated_at;type:timestamp;autoUpdateTime:true"`
	DeletedAt_ DeletedAtTime `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

type ValidPointerTimestamps

type ValidPointerTimestamps struct {
	ValidSince_ Time     `gorm:"column:valid_since;type:timestamp"`
	ValidUpTo_  NullTime `gorm:"column:valid_up_to;type:timestamp"`
}

func NewValidPointerTimestamps

func NewValidPointerTimestamps(validSince time.Time, validUpTo *time.Time) ValidPointerTimestamps

func (*ValidPointerTimestamps) ValidSince

func (d *ValidPointerTimestamps) ValidSince() time.Time

func (*ValidPointerTimestamps) ValidUpTo

func (d *ValidPointerTimestamps) ValidUpTo() *time.Time

type ValidTimestamps

type ValidTimestamps struct {
	ValidSince_ Time `gorm:"column:valid_since;type:timestamp"`
	ValidUpTo_  Time `gorm:"column:valid_up_to;type:timestamp"`
}

func NewValidTimestamps

func NewValidTimestamps(validSince, validUpTo time.Time) ValidTimestamps

func (*ValidTimestamps) ValidSince

func (d *ValidTimestamps) ValidSince() time.Time

func (*ValidTimestamps) ValidUpTo

func (d *ValidTimestamps) ValidUpTo() time.Time

Directories

Path Synopsis
Package pgtest Repository test helpers
Package pgtest Repository test helpers

Jump to

Keyboard shortcuts

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