fxpostgres

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(
	fx.Provide(func(lc fx.Lifecycle, cfg *Config) (Driver, error) {
		driver, err := postgres.New(context.Background(), cfg.URL)
		if err != nil {
			return nil, err
		}
		lc.Append(fx.Hook{
			OnStart: func(ctx context.Context) error {
				return driver.Ping(ctx)
			},
			OnStop: func(context.Context) error {
				driver.Close()
				return nil
			},
		})

		return driver, nil
	}),
	fx.Provide(NewMigrationsRunner),
)

Functions

This section is empty.

Types

type Config

type Config struct {
	URL            string `split_words:"true"`
	MigrationsPath string `split_words:"true"`
}

type Driver

type Driver interface {
	Ping(ctx context.Context) error
	Close()
	CountRows(ctx context.Context, query string, args ...interface{}) (int, error)
	ExecuteQuery(ctx context.Context, query string, args ...interface{}) error
	QueryRow(ctx context.Context, query string, args ...interface{}) (pgx.Row, error)
	QueryRows(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
}

type MigrationsRunner

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

func NewMigrationsRunner

func NewMigrationsRunner(config *Config, logger *zap.Logger, shutdowner fx.Shutdowner) *MigrationsRunner

func (*MigrationsRunner) MigrateDown

func (r *MigrationsRunner) MigrateDown() error

func (*MigrationsRunner) MigrateUp

func (r *MigrationsRunner) MigrateUp() error

Jump to

Keyboard shortcuts

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