db

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectOptions

type ConnectOptions struct {
	DSN                string
	DriverName         string
	Retries            int
	RetryDelay         time.Duration
	ConnectTimeout     time.Duration
	ConnMaxLifetime    time.Duration
	MaxIdleConnections int
	MaxOpenConnections int
}

ConnectOptions config options for database

type DB

type DB struct {
	*sql.DB
}

DB type to wrap sql.DB

type ReaderWriter

type ReaderWriter struct {
	Reader *DB
	Writer *DB
}

ReaderWriter wraps db reader and writer

func NewDbConnection

func NewDbConnection(ctx context.Context, ready *bool, ro ConnectOptions, wo ConnectOptions) *ReaderWriter

NewDbConnection connects to the reader and writer per passed in options, with retries, returning a DBReaderWriter object that contains sql.DB connection

func (*ReaderWriter) GetReaderConn

func (dbs *ReaderWriter) GetReaderConn() *sql.DB

GetReaderConn returns connection to reader

func (*ReaderWriter) GetWriterConn

func (dbs *ReaderWriter) GetWriterConn() *sql.DB

GetWriterConn returns connection to writer

type Settings

type Settings struct {
	User               string `yaml:"USER"`
	Password           string `yaml:"PASSWORD"`
	Port               string `yaml:"PORT"`
	Host               string `yaml:"HOST"`
	Name               string `yaml:"NAME"`
	MaxOpenConnections int    `yaml:"MAX_OPEN_CONNECTIONS"`
	MaxIdleConnections int    `yaml:"MAX_IDLE_CONNECTIONS"`
}

Settings connection settings to postgres db

func (*Settings) BuildConnectionString

func (app *Settings) BuildConnectionString(withSearchPath bool) string

BuildConnectionString builds the connection string to the database - for now same as reader

type Store

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

Store holds the database connection and other stuff.

func NewDbConnectionForTest

func NewDbConnectionForTest(ctx context.Context, settings *Settings, withSearchPath bool) Store

NewDbConnectionForTest use this for tests as we have multiple sessions in parallel and don't want the synced one

func NewDbConnectionFromSettings

func NewDbConnectionFromSettings(ctx context.Context, settings *Settings, withSearchPath bool) Store

NewDbConnectionFromSettings sets up a db connection from the settings, only once

func (*Store) DBS

func (store *Store) DBS() *ReaderWriter

DBS returns the reader and writer databases to connect to

func (*Store) IsReady

func (store *Store) IsReady() bool

IsReady returns if db is ready to connect to

func (*Store) WaitForDB

func (store *Store) WaitForDB(logger zerolog.Logger)

WaitForDB waits 30 seconds for db to become available, and Fatal panic if can't connect.

type Tx

type Tx struct {
	*sql.Tx
}

Tx type to wrap sql.Tx

Jump to

Keyboard shortcuts

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