goose

package
v0.0.0-...-5b57cf1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 7 Imported by: 0

README

Goose

Goose is a package that provides some useful functions to interact with a PostgreSQL database.

Add a migration using a pgx connection as parameter

This package provides a function to register a migration that uses a context and a pgx connection as parameter: AddPgxContextMigration. It allows the use of an sqlc querier to interact with the database easily:


import (
    ...
    "github.com/Scalingo/go-utils/postgresql/goose"
    ...
)

func init() {
	err := goose.AddPgxContextMigration(upCreateNode, downCreateNode)
	if err != nil {
		panic(err)
	}
}

func upMigration(ctx context.Context, conn *pgx.Conn) error {
    // db is the package containing the sqlc querier
    querier := db.New(conn)
    ...
}

func downMigration(ctx context.Context, conn *pgx.Conn) error {
    querier := db.New(conn)
    ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPgxContextMigration

func AddPgxContextMigration(ctx context.Context, upMigration PgxContextMigration, downMigration PgxContextMigration) error

AddPgxContextMigration registers a migration in the goose migrations list using a pgx.Conn instead of a sql.DB It can only be used with a pgx driver

Types

type PgxContextMigration

type PgxContextMigration func(context.Context, *pgx.Conn) error

Jump to

Keyboard shortcuts

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