psql

package module
v0.0.0-...-baef4c2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Common helpers for managing postgres database connections and migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, config Config) (*sql.DB, error)

Open opens a database connection pool to a database server

Types

type Config

type Config struct {
	User           string
	Pass           string
	DBName         string
	Host           string
	SSLMode        string
	MaxConnections int
}

Config contains data source name settings

func (Config) DSN

func (config Config) DSN() string

DSN returns the data source name as a string in the correct format

type Migrator

type Migrator struct {
	Db      *sql.DB
	Migrate *migrate.Migrate
}

Migrator

func NewMigrator

func NewMigrator(ctx context.Context, db *sql.DB, source string) (*Migrator, error)

NewMigrator returns a new database migrator for the given connection using a file path for the migrations source

func (*Migrator) Down

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

MigrateDown run down migrations

func (*Migrator) Force

func (m *Migrator) Force(v int) error

MigrateForce force version

func (*Migrator) Up

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

MigrateUp run up migrations

func (*Migrator) Version

func (m *Migrator) Version() (*Version, error)

MigrateVersion prints the current migration version

type Version

type Version struct {
	Version uint
	Dirty   bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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