postgres

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Driver defines the driver name
	Driver = "postgres"
)

Variables

View Source
var (
	// ErrDBOpen returned when db open fails
	ErrDBOpen = errors.New("error opening database")
	// ErrMigrationLoad returned when migrations cannot be loaded
	ErrMigrationLoad = errors.New("error loading new migrations")
	// ErrCreateDBInstance returned when db instance creation fails
	ErrCreateDBInstance = errors.New("error while creating a new DB instance")
	// ErrDBMigrationFailed returned when db migration fails
	ErrDBMigrationFailed = errors.New("db migration failed")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Name           string `env:"DB_NAME"`
	User           string `env:"DB_USER"`
	Password       string `env:"DB_PASS"`
	Driver         string `env:"DB_DRIVER,default=postgres"`
	Host           string `env:"DB_HOST,default=localhost"`
	Port           int    `env:"DB_PORT,default=5432"`
	SSLMode        string `env:"DB_SSL_MODE,default=disable"`
	MigrationsPath string `env:"DB_MIGRATIONS_PATH"`
}

Config holds database configuration

func NewConfig

func NewConfig() *Config

NewConfig returns the parsed config for postgres from env

func (*Config) GetURI

func (c *Config) GetURI() string

GetURI generates and returns the database URI from the provided config

type Initializer

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

func NewInitializer

func NewInitializer(pg *Postgres) *Initializer

NewInitializer returns a new JetStream Initialiazer

func (*Initializer) AddDependency

func (i *Initializer) AddDependency(dep interface{}) error

AddDependency adds necessary service components as dependencies

func (*Initializer) CanRun

func (i *Initializer) CanRun() bool

CanRun returns true if the component has anything to Run

func (*Initializer) CanStop

func (i *Initializer) CanStop() bool

CanRun returns true if the component has anything to Run

func (*Initializer) Dependencies

func (i *Initializer) Dependencies() []string

Dependencies returns the string names of service components that are required as dependencies for this component

func (*Initializer) Run

func (i *Initializer) Run(ctx context.Context) error

Run start the service component

func (*Initializer) Stop

func (i *Initializer) Stop(ctx context.Context) error

Stop - stops the running

type Postgres

type Postgres struct {
	Handle *sql.DB
	*Config
	// contains filtered or unexported fields
}

Postgres contains database instance

func NewPostgres

func NewPostgres() *Postgres

NewPostgres returns new connection to the postgres db

func (*Postgres) HasInitializer

func (db *Postgres) HasInitializer() bool

func (*Postgres) Initializer

func (db *Postgres) Initializer() component.Initializer

func (*Postgres) Migrate

func (db *Postgres) Migrate() error

Migrate runs all remaining db migrations

Jump to

Keyboard shortcuts

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