crdbx

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 11 Imported by: 11

Documentation

Overview

Package crdbx provides shared functions used to initialize connections with a cockroachdb instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustViperFlags

func MustViperFlags(v *viper.Viper, _ *pflag.FlagSet)

MustViperFlags returns the cobra flags and viper config to prevent code duplication and help provide consistent flags across the applications

func NewDB

func NewDB(cfg Config, tracing bool) (*sql.DB, error)

NewDB will open a connection to the database based on the config provided

Types

type Config

type Config struct {
	Name        string `mapstructure:"name"`
	Host        string `mapstructure:"host"`
	User        string `mapstructure:"user"`
	Password    string `mapstructure:"password"`
	Params      string `mapstructure:"params"`
	URI         string `mapstructure:"uri"`
	Connections struct {
		MaxOpen     int           `mapstructure:"max_open"`
		MaxIdle     int           `mapstructure:"max_idle"`
		MaxLifetime time.Duration `mapstructure:"max_lifetime"`
	}
}

Config is used to configure a new cockroachdb connection

func ConfigFromArgs added in v0.0.2

func ConfigFromArgs(v *viper.Viper, dbName string) Config

ConfigFromArgs returns a crdbx.Config from the provided viper-provided flags.

func (Config) GetURI

func (c Config) GetURI() string

GetURI returns the connection URI, if a config URI is provided that will be returned, otherwise the host, user, password, and params will be put together to make a URI that is returned.

Jump to

Keyboard shortcuts

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