postgresql

package
v0.0.0-...-bbe3df6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package postgresql provides methods to interact with PostgreSQL server

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedPartitionStrategy represents an error indicating that the partitioning strategy on the table is not supported.
	ErrUnsupportedPartitionStrategy = errors.New("unsupported partitioning strategy")

	// ErrTableIsNotPartitioned represents an error indicating the specified table don't have partitioning
	ErrTableIsNotPartitioned = errors.New("table is not partitioned")
)
View Source
var ErrUnkownServerVersion = errors.New("could not find server version")
View Source
var ErrUnsupportedPartitionKeyType = errors.New("unsupported partition key column type")

ErrUnsupportedPartitionKeyType represents an error indicating that the column type for partitioning is not supported.

Functions

func GetDatabaseConnection

func GetDatabaseConnection(c ConnectionSettings) (*pgx.Conn, error)

Types

type ColumnType

type ColumnType string
const (
	Date           ColumnType = "date"
	DateTime       ColumnType = "timestamp"
	DateTimeWithTZ ColumnType = "timestamp with time zone"
	UUID           ColumnType = "uuid"
)

type ConnectionSettings

type ConnectionSettings struct {
	URL              string
	StatementTimeout int
	LockTimeout      int
}

type PartitionResult

type PartitionResult struct {
	ParentTable string
	Schema      string
	Name        string
	LowerBound  string
	UpperBound  string
}

type PgxIface

type PgxIface interface {
	Close(context.Context) error
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	PgConn() *pgconn.PgConn
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

type Postgres

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

func New

func New(logger slog.Logger, conn PgxIface) *Postgres

func (Postgres) AttachPartition

func (p Postgres) AttachPartition(schema, table, parent, lowerBound, upperBound string) error

func (Postgres) CreateTableLikeTable

func (p Postgres) CreateTableLikeTable(schema, table, parent string) error

func (Postgres) DetachPartitionConcurrently

func (p Postgres) DetachPartitionConcurrently(schema, table, parent string) error

DetachPartitionConcurrently detaches specified partition from the parent table. The partition still exists as standalone table after detaching More info: https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DETACH-PARTITION

func (Postgres) DropTable

func (p Postgres) DropTable(schema, table string) error

func (Postgres) FinalizePartitionDetach

func (p Postgres) FinalizePartitionDetach(schema, table, parent string) error

FinalizePartitionDetach finalizes a partition detach operation. It's required when a partition is in "detach pending" status. More info: https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DETACH-PARTITION

func (Postgres) GetColumnDataType

func (p Postgres) GetColumnDataType(schema, table, column string) (ColumnType, error)

func (*Postgres) GetEngineVersion

func (p *Postgres) GetEngineVersion() (int64, error)

func (Postgres) GetPartitionSettings

func (p Postgres) GetPartitionSettings(schema, table string) (strategy, key string, err error)

func (*Postgres) GetServerTime

func (p *Postgres) GetServerTime() (serverTime time.Time, err error)

func (Postgres) IsPartitionAttached

func (p Postgres) IsPartitionAttached(schema, table string) (exists bool, err error)

func (Postgres) IsTableExists

func (p Postgres) IsTableExists(schema, table string) (exists bool, err error)

func (Postgres) ListPartitions

func (p Postgres) ListPartitions(schema, table string) (partitions []PartitionResult, err error)

Jump to

Keyboard shortcuts

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