sql

package
v1.2.115 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRegister = errors.New("register db driver")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	DSN string
	// contains filtered or unexported fields
}

DB represents a connection to a SQL database.

func Open

func Open(dsn string, opts ...DBOption) (*DB, error)

Open returns a new DB.

func (*DB) ApplyOptions

func (o *DB) ApplyOptions(options ...DBOption) *DB

ApplyOptions call apply() for all options one by one

func (*DB) GetDatabase

func (db *DB) GetDatabase() (*sqlx.DB, error)

GetDatabase returns a database instance.

func (*DB) GetDatabaseRetry

func (db *DB) GetDatabaseRetry(ctx context.Context, maxWait time.Duration, failAfter time.Duration) (*sqlx.DB, error)

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

type DBOption

type DBOption interface {
	// contains filtered or unexported methods
}

A DBOption sets options.

func WithDB added in v1.2.99

func WithDB(v DB) DBOption

WithDB sets DB.

func WithDBDSN added in v1.2.99

func WithDBDSN(v string) DBOption

WithDBDSN sets DSN in DB.

func WithDBDb added in v1.2.99

func WithDBDb(v *sqlx.DB) DBOption

WithDBDb sets db in DB.

func WithDBDriverName added in v1.2.99

func WithDBDriverName(v string) DBOption

WithDBDriverName sets driverName in DB.

func WithDBDriverPackage added in v1.2.99

func WithDBDriverPackage(v string) DBOption

WithDBDriverPackage sets driverPackage in DB.

func WithDBLogger added in v1.2.99

func WithDBLogger(v *slog.Logger) DBOption

WithDBLogger sets logger in DB.

func WithDBOpts added in v1.2.99

func WithDBOpts(v struct {
	UseTracedDriver  bool
	TraceOrphans     bool
	OmitArgs         bool
	ForcedDriverName string
}) DBOption

WithDBOpts sets opts in DB. options

func WithDistributedTracing

func WithDistributedTracing() DBOption

WithDistributedTracing will make it so that a wrapped driver is used that supports the opentracing API. Deprecated: remove trace options.

func WithOmitArgsFromTraceSpans

func WithOmitArgsFromTraceSpans() DBOption

WithOmitArgsFromTraceSpans will make it so that query arguments are omitted from tracing spans. Deprecated: remove trace options.

func WithRandomDriverName

func WithRandomDriverName() DBOption

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

func WithTraceOrphans

func WithTraceOrphans() DBOption

WithTraceOrphans will make it so that root spans will be created if a trace could not be found using opentracing's SpanFromContext method. Deprecated: remove trace options.

type DBOptionFunc

type DBOptionFunc func(*DB)

DBOptionFunc wraps a function that modifies DB into an implementation of the DBOption interface.

type EmptyDBOption

type EmptyDBOption struct{}

EmptyDBOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

Jump to

Keyboard shortcuts

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