sql

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// If no override option is provided, this is the name of the wrapped MySQL driver that will be
	// registered when calling MySQLConfig.Connect.
	DefaultWrappedMySQLDriverName = "wrappedMySQL"
)
View Source
const (
	// If no override option is provided, this is the name of the wrapped Postgres driver that will be
	// registered when calling PostgresConfig.Connect.
	DefaultWrappedPgDriverName = "instrumentedPostgres"
)

Variables

This section is empty.

Functions

func WithDriverName added in v0.20.0

func WithDriverName(n string) func(*wrappedSQLOptions)

WithDriverName overrides the default wrapped driver name so that multiple wrapped drivers can be registered at once.

func WithMetricsCollectionFrequency added in v0.20.0

func WithMetricsCollectionFrequency(f time.Duration) func(*wrappedSQLOptions)

WithMetricsCollectionFrequency sets the frequency at which database metrics will be collected and made available in the Prometheus registry. Defaults to 5 seconds.

func WithMetricsRegisterer added in v0.20.0

func WithMetricsRegisterer(r prometheus.Registerer) func(*wrappedSQLOptions)

WithMiddleware sets the Prometheus registerer to the wrapped SQL options. Defaults to the prometheus default registerer.

func WithMiddleware added in v0.20.0

func WithMiddleware(m middleware.Middleware) func(*wrappedSQLOptions)

WithMiddleware adds the provided middleware to the wrapped SQL options. Defaults to log and tracing middleware.

func WithMustRegister added in v0.20.0

func WithMustRegister(r bool) func(*wrappedSQLOptions)

WithMustRegister sets whether or not metrics must register in Prometheus. Defaults to true.

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 MySQLConfig added in v0.18.3

type MySQLConfig struct {
	// Path to the server CA certificate for SSL connections
	CACertPath string
	mysql.Config
}

MySQLConfig adds a path for a CA cert to mysql.Config. When CACertPath is set, NewWrappedMySQL will verify the database identity with the provided CA cert.

func (MySQLConfig) Connect added in v0.20.0

func (c MySQLConfig) Connect(ctx context.Context, options ...WrappedSQLOption) (*sqlx.DB, func() error, error)

Connect uses the given Config struct to establish a connection with the database. See the documentation for WrappedSQLOption functions to configure how the driver gets wrapped. Note that calling Connect multiple times is not allowed with the same driver name option.

If no error occurs, the database connection, and a close function are returned

func (*MySQLConfig) RegisterFlags added in v0.18.3

func (c *MySQLConfig) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers MySQL flags with pflags

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
	Username        string        // The username for the database
	Password        string        // The password for the database
	Database        string        // The name of the database
	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
	ConnectTimeout  time.Duration // Amount of time to wait before timing out
	Port            uint16        // The port on which the database is listening
	SSL             bool          // If true, connect to the database with SSL
}

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, options ...WrappedSQLOption) (*sqlx.DB, func() error, error)

Connect uses the given Config struct to establish a connection with the database. See the documentation for WrappedSQLOption functions to configure how the driver gets wrapped. Note that calling Connect multiple times is not allowed with the same driver name option.

If no error occurs, the database connection, and a close function are returned

func (*PostgresConfig) RegisterFlags

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

RegisterFlags registers PostgreSQL flags with pflags

type WrappedSQLOption added in v0.20.0

type WrappedSQLOption func(*wrappedSQLOptions)

WrappedSQLOption is a function that adds configuration for wrapping both PostgreSQL and MySQL drivers.

Directories

Path Synopsis
Package middleware provides hooks that are called when executing sql queries.
Package middleware provides hooks that are called when executing sql queries.

Jump to

Keyboard shortcuts

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