sql

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWrappedMySQL added in v0.16.0

func NewWrappedMySQL(
	ctx context.Context,
	config mysql.Config,
	middleware middleware.Middleware,
	registry prometheus.Registerer,
	mustRegister bool,
	collectionFrequency time.Duration,
) (*sql.DB, func() error, error)

NewWrappedMySQLDrive builds a MySQL driver wrapped with the provided middleware and starts a periodic task that collects database connection metrics in the provided prometheus registerer. The returned function should be called close the database connection instead of calling Close() directly as it stops the periodic metrics task.

Types

type DBConnector

type DBConnector interface {
	Connect() error
}

DBConnector is the interface which various Database-specific configuration objects must satisfy to return a usable database connection to the caller

type PostgresConfig

type PostgresConfig struct {
	ApplicationName  string                // The name of the application connecting. Useful for attributing db load.
	Host             string                // The host where the database is located
	Port             uint16                // The port on which the database is listening
	Username         string                // The username for the database
	Password         string                // The password for the database
	Database         string                // The name of the database
	ConnectTimeout   time.Duration         // Amount of time to wait before timing out
	SSL              bool                  // If true, connect to the database with SSL
	SSLCert          string                // Path to the SSL Certificate, if any
	SSLKey           string                // Path to the SSL Key, if any
	SSLRootCert      string                // Path to the SSL Root Certificate, if any
	MetricsFrequency time.Duration         // How often to export core database metrics
	Middleware       middleware.Middleware // List of SQL Middlewares to apply, if any
}

PostgresConfig defines Postgres SQL connection information

func NewDefaultPostgresConfig

func NewDefaultPostgresConfig(appName, dbName string) PostgresConfig

NewDefaultPostgresConfig creates and return a default postgres configuration.

func (PostgresConfig) Connect

func (pc PostgresConfig) Connect(ctx context.Context, registry prometheus.Registerer, mustRegister bool) (*sqlx.DB, func(), error)

Connect uses the given Config struct to establish a connection with the database. Optionally, a prometheus registry may be provided. If no registry is provided, the global registry will be used. Additionally, users may specify that failed metrics registration should result in a panic via the `mustRegister` flag.

The database connection, deferable close function, and error are returned

func (*PostgresConfig) RegisterFlags

func (pc *PostgresConfig) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers SQL flags with pflags

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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