postgres

package
v0.0.0-...-8081bc5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg Config) (*sqlx.DB, error)

Connect creates a connection to the PostgreSQL instance.

func Setup

func Setup(cfg Config, migrations migrate.MemoryMigrationSource) (*sqlx.DB, error)

Setup creates a connection to the PostgreSQL instance and applies any unapplied database migrations. A non-nil error is returned to indicate failure.

func SetupWithConfig

func SetupWithConfig(migrations migrate.MemoryMigrationSource, cfg Config) (*sqlx.DB, error)

SetupWithConfig creates a connection to the PostgreSQL instance and applies any unapplied database migrations. A non-nil error is returned to indicate failure.

Types

type Config

type Config struct {
	Host        string `env:"HOST"           envDefault:"localhost"`
	Port        string `env:"PORT"           envDefault:"5432"`
	User        string `env:"USER"           envDefault:"absmach"`
	Pass        string `env:"PASS"           envDefault:"absmach"`
	Name        string `env:"NAME"           envDefault:""`
	SSLMode     string `env:"SSL_MODE"       envDefault:"disable"`
	SSLCert     string `env:"SSL_CERT"       envDefault:""`
	SSLKey      string `env:"SSL_KEY"        envDefault:""`
	SSLRootCert string `env:"SSL_ROOT_CERT"  envDefault:""`
}

type Database

type Database interface {
	// NamedQueryContext executes a named query against the database and returns
	NamedQueryContext(context.Context, string, interface{}) (*sqlx.Rows, error)

	// NamedExecContext executes a named query against the database and returns
	NamedExecContext(context.Context, string, interface{}) (sql.Result, error)

	// QueryRowxContext queries the database and returns an *sqlx.Row.
	QueryRowxContext(context.Context, string, ...interface{}) *sqlx.Row

	// QueryxContext queries the database and returns an *sqlx.Rows and an error.
	QueryxContext(context.Context, string, ...interface{}) (*sqlx.Rows, error)

	// QueryContext queries the database and returns an *sql.Rows and an error.
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

	// ExecContext executes a query without returning any rows.
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)

	// BeginTxx begins a transaction and returns an *sqlx.Tx.
	BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
}

Database provides a database interface.

func NewDatabase

func NewDatabase(db *sqlx.DB, config Config, tracer trace.Tracer) Database

NewDatabase creates a Clients'Database instance.

Jump to

Keyboard shortcuts

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