Help us shape the future of Go! Take the 2026 Go Developer Survey

driver

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MysqlErrorText = "access denied for user"
	PgErrorText    = "password authentication failed for user"
)

Variables

View Source
var (
	ErrConfigRequired   = errors.New("config is required")
	ErrNoNilCredentials = errors.New("store cannot return nil credentials")
	ErrMissingUsername  = errors.New("missing username")
	ErrMissingPassword  = errors.New("missing password")
)
View Source
var MySQLAuthError = errorTester(MysqlErrorText) //nolint:gochecknoglobals

MySQLAuthError tests whether an error from MySQL is an authentication failure.

View Source
var PostgreSQLAuthError = errorTester(PgErrorText) //nolint:gochecknoglobals

PostgreSQLAuthError tests whether an error from PostgreSQL is an authentication failure.

Functions

func MysqlFormatter

func MysqlFormatter(username, password, host string, port int, db string, opts map[string]string) string

MysqlFormatter formats a connection string for the go-sql-driver/mysql lib NOTE: Currently only supports TCP connections.

func PgFormatter

func PgFormatter(username, password, host string, port int, db string, opts map[string]string) string

PgFormatter formats a connection URI for the pq and pgx lib.

func PgKVFormatter

func PgKVFormatter(username, password, host string, port int, db string, opts map[string]string) string

PgKVFormatter formats a connection string in the K/V format.

func Register

func Register(name string, f factory) error

Register registers a DB driver Note: Register behaves similarly to database/sql.Register except that it doesn't panic on duplicate registrations, it just ignores them and continues. The reason we Register drivers separately from database/sql is because

a) most DB drivers already call database/sql.Register in an init() func
b) we need to carry a lot more information along with the driver to ensure our
   connector logic works correctly.

Types

type AuthError

type AuthError func(e error) bool

AuthError is a func to evaluate the DB-specific error string that indicates an authentication error.

type Config

type Config struct {
	Opts      map[string]string
	Formatter Formatter
	Host      string
	DB        string
	Port      int
	Retries   int
}

Config is a struct that holds non-credential database configuration.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector represents a driver in a fixed configuration.

func NewConnector

func NewConnector(s Store, driverName string, cfg *Config) (*Connector, error)

NewConnector creates a new connector from a store.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

Connect implements driver.Connector interface.

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver implements driver.Connector interface.

type Credentials

type Credentials interface {
	GetUsername() string
	GetPassword() string
}

Credentials represents an abstraction over a username and password.

type Driver

type Driver struct {
	Driver    driver.Driver
	Formatter Formatter
	AuthError AuthError
}

Driver carries information along with a database/sql/driver required for creating a Connector

func CreateDriver

func CreateDriver(name string) (*Driver, error)

CreateDriver creates a Driver.

type Formatter

type Formatter func(username string, password string, host string, port int, db string, opts map[string]string) string

Formatter takes connection string components and assembles them into an implementation-specific conn string/DSN.

type Store

type Store interface {
	Get(ctx context.Context) (Credentials, error)
	Refresh(ctx context.Context) (Credentials, error)
}

Store represents a mechanism for retrieving Credentials.

Jump to

Keyboard shortcuts

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