pgdb

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbPool *pgxpool.Pool

DbPool is PGX pool connection, initiated by ConnectPgxPool. Do not use before the initialization.

View Source
var Qb adaptedStatementBuilder

Qb is the query builder exported, initiated from either ConnectStdLib or ConnectPgxPool

View Source
var StdDb *sql.DB

StdDb is pgx's stadard library SQL adaptor, initiated by ConnectStdLib. Do not use before the initialization.

Functions

func ConnectPgxPool

func ConnectPgxPool(ctx context.Context, c Config) error

ConnectPgxPool initializes the PGX pool connection

func ConnectStdLib

func ConnectStdLib(ctx context.Context, c Config) error

ConnectStdLib initiate the connection to database with pgx stdlib

func Exec added in v0.0.6

func Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)

Query runs the qeuery using the default DbPool

func MigrateEntryPoint

func MigrateEntryPoint(config Config, optionally1EmbeddedDirs ...embed.FS)

MigrateEntryPoint is the entrypoint for DB migration commands. If config.MigrationFromEmbedded is true, the (optional) embedded migration directory must then be set (only 1 is accepted)

the simplest way to include the embed:

import "embed"
//go:embed migrations
var embeddedMigrations embed.FS

func MigrateGetDbDriver added in v0.0.4

func MigrateGetDbDriver(ctx context.Context, c Config) (pgDatabaseDriver database.Driver, err error)

MigrateGetDbDriver exposes the lower-level migration integration

func MigrateGetInstance added in v0.0.4

func MigrateGetInstance(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrateInstance *migrate.Migrate, err error)

MigrateGetInstance exposes the lower-level migration integration

func MigrateGetSource added in v0.0.4

func MigrateGetSource(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationSourceDriver source.Driver, err error)

MigrateGetSource exposes the lower-level migration integration

func MigrateGetSourceFs added in v0.0.5

func MigrateGetSourceFs(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationFS fs.FS, err error)

MigrateGetSourceFs exposes the lower-level migration integration

func QbExec added in v0.0.6

func QbExec(ctx context.Context, builtQuery sq.Sqlizer) (pgconn.CommandTag, error)

QbExec takes a finished Squirrel's query builder and perform it using the default DbPool

func QbQuery added in v0.0.6

func QbQuery(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Rows, error)

QbQuery takes a finished Squirrel's query builder and perform query using the default DbPool

func QbQueryRow added in v0.0.6

func QbQueryRow(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Row, error)

DoQuQeryRow takes a finished Squirrel's query builder and perform query using the default DbPool

func Query added in v0.0.6

func Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query runs the qeuery using the default DbPool

func QueryRow added in v0.0.6

func QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

QueryRow runs the qeuery using the default DbPool retrieving 1 row

Types

type Config

type Config struct {
	Host                             string `yaml:"Host" env:"PG_HOST"`
	Port                             int    `yaml:"Port" env:"PG_PORT"`
	Database                         string `yaml:"Database" env:"PG_DATABASE"`
	Username                         string `yaml:"Username" env:"PG_USERNAME"`
	Password                         string `yaml:"Password" env:"PG_PASSWORD"`
	SSL                              string `yaml:"SSL" env:"PG_SSL"`
	MigrationStatementTimeoutSeconds int    `yaml:"MigrationStatementTimeoutSeconds" env:"PG_MIGRATION_STATEMENT_TIMEOUT_SECONDS"`
	MigrationFromEmbedded            bool   `yaml:"MigrationFromEmbedded" env:"PG_MIGRATION_FROM_EMBEDDED"`
	MigrationDirectory               string `yaml:"MigrationDirectory" env:"PG_MIGRATION_DIRECTORY"`
}

func (Config) GetDsn

func (c Config) GetDsn() string

Jump to

Keyboard shortcuts

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