database

package
v0.0.0-...-065a81b Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: CC0-1.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect() *sql.DB

func ConnectPool

func ConnectPool() *pgxv5Pool.Pool

func CreatePgxv5DB

func CreatePgxv5DB(cfg *Config) (*pgxv5Pool.Pool, error)

Types

type Config

type Config struct {
	MaxOpenConns       int `conf:"BCDA_DB_MAX_OPEN_CONNS" conf_default:"60"`
	MaxIdleConns       int `conf:"BCDA_DB_MAX_IDLE_CONNS" conf_default:"40"`
	ConnMaxLifetimeMin int `conf:"BCDA_DB_CONN_MAX_LIFETIME_MIN" conf_default:"5"`
	ConnMaxIdleTime    int `conf:"BCDA_DB_CONN_MAX_IDLE_TIME" conf_default:"30"`

	DatabaseURL string `conf:"DATABASE_URL"`

	HealthCheckSec int `conf:"DB_HEALTH_CHECK_INTERVAL" conf_default:"5"`
}

func LoadConfig

func LoadConfig() (cfg *Config, err error)

Loads database URLs from environment variables.

type DB

type DB struct {
	*sql.DB
}

DB is a wrapper around *sql.DB to allow us to implement our internal interfaces

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

type Executable

type Executable interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
}

type Queryable

type Queryable interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
}

type Result

type Result interface {
	RowsAffected() (int64, error)
}

Result is an interface around https://golang.org/pkg/database/sql/#Result. It can be implemented by other database libraries (like pgx)

type Row

type Row interface {
	Scan(dest ...interface{}) error
}

Row is an interface around https://golang.org/pkg/database/sql/#Row. It can be implemented by other database libraries (like pgx)

type Rows

type Rows interface {
	Close() error
	Err() error
	Next() bool
	Scan(dest ...interface{}) error
}

Rows is an interface around https://golang.org/pkg/database/sql/#Rows. It can be implemented by other database libraries (like pgx)

type Tx

type Tx struct {
	*sql.Tx
}

Tx is a wrapper around *sql.DB to allow us to implement our internal interfaces

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

func (*Tx) QueryRowContext

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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