psqlutil

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package psqlutil provides PostgreSQL utility functions, offering the most common operations in the PSQL ecosystem.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnableToResolveCaller is returned when the caller CWD cannot be retrieved.
	ErrUnableToResolveCaller = errors.New("unable to resolve caller")

	// ErrProjectRootNotFound is returned when the
	// project root is not found.
	ErrProjectRootNotFound = errors.New("project root not found")
)

Functions

func ComposeDSN deprecated added in v0.0.4

func ComposeDSN(
	host,
	port,
	user,
	password,
	dbName,
	sslMode string,
) string

ComposeDSN returns a PostgreSQL Data Source Name.

Deprecated: Use github.com/purposeinplay/go-commons/psqlutil.ConnectionConfig instead.

func FindSQLDir added in v0.0.6

func FindSQLDir() (string, error)

FindSQLDir attempts to compose the path to the sql directory in the project. nolint: gocognit // allow high cog complexity.

func GormOpen

func GormOpen(
	ctx context.Context,
	zapLogger *zap.Logger,
	postgresDSN string,
	ignoreRecordNotFoundErr bool,
) (*gorm.DB, error)

GormOpen opens a new db connection and returns a *gorm.DB.

func MustNewSQL

func MustNewSQL(db *sql.DB, err error) *sql.DB

MustNewSQL panics if err is not nil, otherwise it returns db.

func ReadSchema added in v0.0.2

func ReadSchema() (string, error)

ReadSchema reads schema dynamically based on the CWD of the caller.

func SQLOpen added in v0.0.5

func SQLOpen(
	ctx context.Context,
	driver,
	postgresDSN string,
) (*sql.DB, error)

SQLOpen opens a new db connection and returns a *sql.DB with a gorm driver.

Types

type ConnectionConfig added in v0.0.9

type ConnectionConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	SSLMode  string
}

ConnectionConfig is a PostgreSQL connection configuration.

func (ConnectionConfig) DSN added in v0.0.9

func (c ConnectionConfig) DSN() string

DSN returns a PostgreSQL Data Source Name.

Jump to

Keyboard shortcuts

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