sqlcon

package
v0.0.0-...-6b3764c Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DriverPostgreSQL = "postgres"
	DriverMySQL      = "mysql"
)

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(db *sqlx.DB, fn TxFn) (err error)

WithTransaction creates a new transaction and handles rollback/commit based on the error object returned by the `TxFn`

Types

type OptionModifier

type OptionModifier func(*options)

OptionModifier is a wrapper for options.

func WithAllowRoot

func WithAllowRoot() OptionModifier

WithAllowRoot will make it so that root spans will be created if a trace could not be found using opentracing's SpanFromContext method.

func WithDistributedTracing

func WithDistributedTracing() OptionModifier

WithDistributedTracing will make it so that a wrapped driver is used that supports the opentracing API.

func WithOmitArgsFromTraceSpans

func WithOmitArgsFromTraceSpans() OptionModifier

WithOmitArgsFromTraceSpans will make it so that query arguments are omitted from tracing spans.

func WithRandomDriverName

func WithRandomDriverName() OptionModifier

WithRandomDriverName is specifically for writing tests as you can't register a driver with the same name more than once.

type SQLConnection

type SQLConnection struct {
	URL *url.URL
	L   logrus.FieldLogger
	// contains filtered or unexported fields
}

SQLConnection represents a connection to a SQL database.

func NewSQLConnection

func NewSQLConnection(db string, l logrus.FieldLogger, opts ...OptionModifier) (*SQLConnection, error)

NewSQLConnection returns a new SQLConnection.

func (*SQLConnection) GetDatabase

func (c *SQLConnection) GetDatabase() (*sqlx.DB, error)

GetDatabase retrusn a database instance.

func (*SQLConnection) GetDatabaseRetry

func (c *SQLConnection) GetDatabaseRetry(maxWait time.Duration, failAfter time.Duration) (*sqlx.DB, error)

GetDatabaseRetry tries to connect to a database and fails after failAfter.

type TxFn

type TxFn func(tx *sqlx.Tx) error

A Txfn is a function that will be called with an initialized `Transaction` object that can be used for executing statements and queries against a database.

Jump to

Keyboard shortcuts

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