Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MigrationDir = "migrations"
)

Variables

This section is empty.

Functions

func MigrateContext added in v0.3.18

func MigrateContext(ctx context.Context, db *gorm.DB) (result error)

MigrateContext applies migrations on a reserved connection without closing the caller's database pool. golang-migrate uses background contexts for several queries, including advisory-lock acquisition and version-table setup. Closing this connection's transport on cancellation interrupts those queries.

func WithInitializationLock added in v0.3.18

func WithInitializationLock(ctx context.Context, db *gorm.DB, initialize func() error) (result error)

WithInitializationLock serializes initialization across PostgreSQL clients. The callback must finish its database work before returning.

Types

type PostgresDBConnector

type PostgresDBConnector struct {
	DSN       string
	TLSConfig *_tls.TLSConfig
	// contains filtered or unexported fields
}

func NewPostgresDBConnector

func NewPostgresDBConnector(
	dsn string,
	tlsConfig *_tls.TLSConfig,
) *PostgresDBConnector

func (*PostgresDBConnector) BuildDSNWithTLS

func (c *PostgresDBConnector) BuildDSNWithTLS() (string, error)

BuildDSNWithTLS builds a PostgreSQL DSN with SSL/TLS parameters based on the TLS configuration

func (*PostgresDBConnector) Connect

func (c *PostgresDBConnector) Connect() (*gorm.DB, error)

func (*PostgresDBConnector) ConnectContext added in v0.3.18

func (c *PostgresDBConnector) ConnectContext(ctx context.Context) (*gorm.DB, error)

ConnectContext bounds connection attempts and retry delays by ctx. The returned database handle remains usable after ctx is canceled.

func (*PostgresDBConnector) DB

func (c *PostgresDBConnector) DB() *gorm.DB

func (*PostgresDBConnector) WithMaxRetries

func (c *PostgresDBConnector) WithMaxRetries(maxRetries int) *PostgresDBConnector

type PostgresMigrator

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

func NewPostgresMigrator

func NewPostgresMigrator(db *gorm.DB) (*PostgresMigrator, error)

func (*PostgresMigrator) Down

func (m *PostgresMigrator) Down(steps *int) error

func (*PostgresMigrator) Migrate

func (m *PostgresMigrator) Migrate() error

func (*PostgresMigrator) Up

func (m *PostgresMigrator) Up(steps *int) error

Jump to

Keyboard shortcuts

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