providerregistry

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package providerregistry maps database driver names to provider factories.

Index

Constants

View Source
const PoolerTransaction = "transaction"

PoolerTransaction is the transaction-mode pooler setting.

Variables

View Source
var ErrNoLimits = errors.New("providerregistry: the driver declares no limits")

ErrNoLimits is returned for a driver that registered no LimitsFunc.

View Source
var ErrUnsupportedDriver = errors.New("providerregistry: unsupported driver")

ErrUnsupportedDriver is returned when no factory is registered for a driver.

Functions

func Drivers added in v0.1.15

func Drivers() []string

Drivers lists the registered driver names, sorted.

func HasLimits added in v0.1.15

func HasLimits(driver string) bool

HasLimits reports whether driver registered a LimitsFunc.

func IsRegistered

func IsRegistered(driver string) bool

IsRegistered reports whether driver has a registered factory.

func Limits added in v0.1.15

func Limits(driver, dsn string, opts Options) (dialect.Profile, error)

Limits judges a connection of driver to dsn opened with opts, without connecting (see LimitsFunc).

func New

func New(driver, dsn string, opts Options) (provider.Provider, error)

New opens the provider registered under driver.

func Register

func Register(name string, factory Factory)

Register adds a named provider factory. It panics for invalid or duplicate registrations so built-in driver mistakes fail during process startup.

func RegisterLimits added in v0.1.15

func RegisterLimits(name string, fn LimitsFunc)

RegisterLimits adds the LimitsFunc of a driver. Like Register, it panics for invalid or duplicate registrations.

Types

type Factory

type Factory func(dsn string, opts Options) (provider.Provider, error)

Factory opens a database provider.

type LimitsFunc added in v0.1.15

type LimitsFunc func(dsn string, opts Options) (dialect.Profile, error)

LimitsFunc judges, without connecting, what a connection to dsn opened with opts guarantees on the server (its statement timeouts and native write refusals).

type Options added in v0.1.11

type Options struct {
	// Timeout is the statement timeout the provider sets natively.
	Timeout time.Duration
	// Pooler is "transaction" when the connection goes through a
	// transaction-mode pooler, which keeps no session state: the provider
	// must not rely on named prepared statements or startup settings.
	Pooler string
	// Context bounds opening the provider (its first connection); nil means
	// no bound.
	Context context.Context
}

Options configures an opened provider.

func (Options) NativeTimeout added in v0.1.15

func (o Options) NativeTimeout() time.Duration

NativeTimeout is the statement timeout a provider sets on the database: Timeout less a margin (a tenth, at most a second), so the database stops a slow statement, and reports it stopped, before the request's own deadline cuts the connection and leaves a write's outcome unknown. The request's deadline starts before planning, so this makes the database usually, not always, the first to stop. Configuration keeps Timeout at config.MinQueryTimeout or more, which leaves the margin whole milliseconds; a shorter Timeout given in code still gets at least a millisecond, as 0 is no timeout at all on PostgreSQL.

func (Options) OpenContext added in v0.1.12

func (o Options) OpenContext() context.Context

OpenContext is the context opening the provider runs under.

Jump to

Keyboard shortcuts

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