storage

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsurePostgresSearchPathInURL

func EnsurePostgresSearchPathInURL(connURL, namespace string) (string, error)

EnsurePostgresSearchPathInURL ensures postgres / postgresql URLs include search_path matching the auth schema (DB_NAMESPACE). Pop issues unqualified DDL for schema_migrations; PostgreSQL 15+ rejects CREATE when the session search_path is empty.

func TightenPoolForMigration

func TightenPoolForMigration(db *pop.Connection)

TightenPoolForMigration sets the underlying sql.DB pool to a single connection so session SET search_path (and Pop migrator queries) stay on the same connection.

func TryAlterDatabaseSearchPathDefault

func TryAlterDatabaseSearchPathDefault(db *pop.Connection, namespace string) error

TryAlterDatabaseSearchPathDefault sets ALTER DATABASE ... SET search_path so every new session on this database gets a non-empty search_path. That fixes Pop migrations when pooled connections do not inherit a prior SET search_path on another connection. Fails silently on permission errors (managed Postgres); callers can log and continue.

Types

type Advisor

type Advisor struct {
	StatsFunc  func() sql.DBStats
	AdviseFunc func(Advisory)
	Interval   time.Duration

	Stats         sql.DBStats
	LastAdvisedAt time.Time

	Iterations int

	WaitDurationSamples []time.Duration
	WaitCountSamples    []int64
}

func (*Advisor) Start

func (a *Advisor) Start(observeDuration time.Duration)

type Advisory

type Advisory struct {
	LongWaitDurationSamples int
	Over2WaitingSamples     int
}

type CommitWithError

type CommitWithError struct {
	Err error
}

func NewCommitWithError

func NewCommitWithError(err error) *CommitWithError

NewCommitWithError creates an error that can be returned in a pop transaction without rolling back the transaction. This should only be used in cases where you want the transaction to commit but return an error message to the user.

func (*CommitWithError) Cause

func (e *CommitWithError) Cause() error

func (*CommitWithError) Error

func (e *CommitWithError) Error() string

type ConnLimits

type ConnLimits struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
	ServerMaxConns  int
	Strategy        string
}

ConnLimits represents the connection limits for the underlying *sql.DB.

type Connection

type Connection struct {
	*pop.Connection
	// contains filtered or unexported fields
}

Connection is the interface a storage provider must implement. Do not copy a storage connection

func Dial

func Dial(config *conf.GlobalConfiguration) (*Connection, error)

Dial will connect to that storage engine

func DialContext

func DialContext(
	ctx context.Context,
	config *conf.GlobalConfiguration,
) (*Connection, error)

func DialWithRetry added in v1.4.0

func DialWithRetry(ctx context.Context, dial dialFunc) (*Connection, error)

DialWithRetry dials the database, waiting through transient failures until ctx is done.

Every attempt is logged with the elapsed total, so a database that has been unreachable for ten minutes reads as exactly that rather than as a server that quietly stopped trying.

func (*Connection) ApplyConfig

func (c *Connection) ApplyConfig(
	ctx context.Context,
	config *conf.GlobalConfiguration,
	le *logrus.Entry,
) error

ApplyConfig will apply the given config to this *Connection, potentially adjusting the underlying *sql.DB's current settings.

When config.DB.ConnPercentage is set to a non-zero value ApplyConfig attempts to set the MaxOpenConns and MaxIdleConns to a percentage based value. It does this by opening a connection to the server and calling `SHOW max_connections;` to determine the connection limits. If this operation fails it applies no configuration changes at all and returns an error.

func (*Connection) Copy

func (c *Connection) Copy() *Connection

Copy will return a copy of this connection. It must be instead of using a struct literal from external packages.

func (*Connection) Transaction

func (c *Connection) Transaction(fn func(*Connection) error) error

func (*Connection) UpdateOnly

func (conn *Connection) UpdateOnly(model interface{}, includeColumns ...string) error

func (*Connection) WithContext

func (c *Connection) WithContext(ctx context.Context) *Connection

WithContext returns a new connection with an updated context. This is typically used for tracing as the context contains trace span information.

type NullString

type NullString string

func (*NullString) Scan

func (s *NullString) Scan(value interface{}) error

func (NullString) String

func (s NullString) String() string

func (NullString) Value

func (s NullString) Value() (driver.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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