Documentation
¶
Index ¶
- Constants
- Variables
- func OpenMigrationDB(conn *Connection) (*sql.DB, error)
- func OpenPool(ctx context.Context, conn *Connection, mp metric.MeterProvider, ...) (*pgxpool.Pool, error)
- func Query[T any](ctx context.Context, tx Querier, query string, ...) ([]T, error)
- func RunMigrations(ctx context.Context, log *slog.Logger, conn *Connection, name string, ...) (retErr error)
- func RunMigrationsOn(ctx context.Context, log *slog.Logger, db *sql.DB, name string, ...) error
- type Connection
- func (*Connection) Descriptor() ([]byte, []int)deprecated
- func (x *Connection) GetDsn() string
- func (x *Connection) GetPassword() string
- func (x *Connection) GetTls() *TLS
- func (x *Connection) GetUser() string
- func (*Connection) ProtoMessage()
- func (x *Connection) ProtoReflect() protoreflect.Message
- func (x *Connection) Reset()
- func (x *Connection) String() string
- type ConnectionDirectory
- type Database
- type PoolOption
- func WithAfterConnect(fn func(context.Context, *pgx.Conn) error) PoolOption
- func WithAttrs(attrs ...attribute.KeyValue) PoolOption
- func WithConnectTimeout(d time.Duration) PoolOption
- func WithMaxConns(n int32) PoolOption
- func WithMinConns(n int32) PoolOption
- func WithQueryTracer(tracer pgx.QueryTracer) PoolOption
- type Querier
- type TLS
- func (x *TLS) ClientCertificates() ([]tls.Certificate, error)
- func (*TLS) Descriptor() ([]byte, []int)deprecated
- func (x *TLS) GetCaCertificate() string
- func (x *TLS) GetCertificate() string
- func (x *TLS) GetKey() string
- func (x *TLS) IsEmpty() bool
- func (*TLS) ProtoMessage()
- func (x *TLS) ProtoReflect() protoreflect.Message
- func (x *TLS) Reset()
- func (x *TLS) RootCAs() (*x509.CertPool, error)
- func (x *TLS) String() string
Constants ¶
const PoolNameAttr attribute.Key = "pool"
PoolNameAttr labels otelpgx stats metrics so multiple pools pointing at the same host:port/database can be distinguished in metrics backends.
Variables ¶
var File_internal_tool_pgtool_connection_proto protoreflect.FileDescriptor
Functions ¶
func OpenMigrationDB ¶ added in v19.4.0
func OpenMigrationDB(conn *Connection) (*sql.DB, error)
OpenMigrationDB opens a database/sql handle for goose, which coordinates with a session-level advisory lock and so needs a session rather than a pooled connection. Credentials are applied per connection, as for a pool.
func OpenPool ¶
func OpenPool(ctx context.Context, conn *Connection, mp metric.MeterProvider, tp trace.TracerProvider, opts ...PoolOption) (*pgxpool.Pool, error)
OpenPool opens a pgxpool.Pool from cfg with otelpgx tracing and stats wiring. opts may override fields on the parsed pgxpool.Config.
func RunMigrations ¶
func RunMigrations(ctx context.Context, log *slog.Logger, conn *Connection, name string, migrationsFS fs.FS) (retErr error)
RunMigrations applies pending migrations from migrationsFS using goose.
func RunMigrationsOn ¶ added in v19.4.0
func RunMigrationsOn(ctx context.Context, log *slog.Logger, db *sql.DB, name string, migrationsFS fs.FS) error
RunMigrationsOn applies pending migrations on a handle the caller already holds, for callers that obtain one without naming a Connection. The handle must bypass PgBouncer because goose relies on session-level pg_advisory_lock for cross-replica coordination. name scopes goose's tracking table so multiple modules can share the same database without colliding. It does not scope the advisory lock: goose's session locker uses one fixed id, so modules migrating the same database serialize against each other.
Types ¶
type Connection ¶ added in v19.4.0
type Connection struct {
Dsn string `protobuf:"bytes,1,opt,name=dsn" json:"dsn,omitempty"`
User string `protobuf:"bytes,2,opt,name=user" json:"user,omitempty"`
Password string `protobuf:"bytes,3,opt,name=password" json:"password,omitempty"`
Tls *TLS `protobuf:"bytes,4,opt,name=tls" json:"tls,omitempty"`
// contains filtered or unexported fields
}
func (*Connection) Descriptor
deprecated
added in
v19.4.0
func (*Connection) Descriptor() ([]byte, []int)
Deprecated: Use Connection.ProtoReflect.Descriptor instead.
func (*Connection) GetDsn ¶ added in v19.4.0
func (x *Connection) GetDsn() string
func (*Connection) GetPassword ¶ added in v19.4.0
func (x *Connection) GetPassword() string
func (*Connection) GetTls ¶ added in v19.4.0
func (x *Connection) GetTls() *TLS
func (*Connection) GetUser ¶ added in v19.4.0
func (x *Connection) GetUser() string
func (*Connection) ProtoMessage ¶ added in v19.4.0
func (*Connection) ProtoMessage()
func (*Connection) ProtoReflect ¶ added in v19.4.0
func (x *Connection) ProtoReflect() protoreflect.Message
func (*Connection) Reset ¶ added in v19.4.0
func (x *Connection) Reset()
func (*Connection) String ¶ added in v19.4.0
func (x *Connection) String() string
type ConnectionDirectory ¶ added in v19.4.0
type ConnectionDirectory struct {
// contains filtered or unexported fields
}
ConnectionDirectory resolves database connections from a directory of connection files, each named after the database it describes. The caller picks the naming scheme; autocore names each file after its workflow database's db_id, so its central registry can store no connection details at all.
func NewConnectionDirectory ¶ added in v19.4.0
func NewConnectionDirectory(dir string, validator protovalidate.Validator) (*ConnectionDirectory, error)
NewConnectionDirectory opens the directory if it is there. An absent one is not an error: a deployment with no databases registered yet has nothing to mount, and a database that does need a file fails on its own when something asks for it. Files are read on demand, so a malformed one likewise fails only the database it describes.
func (*ConnectionDirectory) Resolve ¶ added in v19.4.0
func (d *ConnectionDirectory) Resolve(name string) (*Database, error)
Resolve reads the connection file named name, yielding the runtime and migration connections. Callers resolve once and hold the result, so an edit to a file takes effect the next time the caller resolves.
Nothing enumerates the directory: a file is only ever opened by the name asked for, so keys that are not connection files cannot affect one that is.
type Database ¶ added in v19.4.0
type Database struct {
Runtime *Connection `protobuf:"bytes,1,opt,name=runtime" json:"runtime,omitempty"`
Migration *Connection `protobuf:"bytes,2,opt,name=migration" json:"migration,omitempty"`
// contains filtered or unexported fields
}
func ConnectionFromFile ¶ added in v19.4.0
func ConnectionFromFile(path string, validator protovalidate.Validator) (*Database, error)
ConnectionFromFile reads the connection file describing one database, in the same format as one file of a ConnectionDirectory. For a database named directly by the configuration rather than looked up by name.
func (*Database) Descriptor
deprecated
added in
v19.4.0
func (*Database) GetMigration ¶ added in v19.4.0
func (x *Database) GetMigration() *Connection
func (*Database) GetRuntime ¶ added in v19.4.0
func (x *Database) GetRuntime() *Connection
func (*Database) ProtoMessage ¶ added in v19.4.0
func (*Database) ProtoMessage()
func (*Database) ProtoReflect ¶ added in v19.4.0
func (x *Database) ProtoReflect() protoreflect.Message
type PoolOption ¶
type PoolOption func(*poolOptionConfig)
PoolOption overrides fields on the pgxpool.Config parsed from the DSN before the pool is opened.
func WithAfterConnect ¶ added in v19.2.0
WithAfterConnect sets a callback run on every new connection once it is established, e.g. to apply per-session SET statements.
func WithAttrs ¶ added in v19.1.0
func WithAttrs(attrs ...attribute.KeyValue) PoolOption
func WithConnectTimeout ¶ added in v19.4.0
func WithConnectTimeout(d time.Duration) PoolOption
WithConnectTimeout bounds establishing each connection, from the dial through TLS and authentication.
func WithMaxConns ¶
func WithMaxConns(n int32) PoolOption
WithMaxConns overrides the pool's MaxConns.
func WithMinConns ¶
func WithMinConns(n int32) PoolOption
WithMinConns overrides the pool's MinConns.
func WithQueryTracer ¶ added in v19.4.0
func WithQueryTracer(tracer pgx.QueryTracer) PoolOption
WithQueryTracer adds a tracer alongside the OpenTelemetry one. Batched statements reach it only if it also implements pgx.BatchTracer.
type TLS ¶ added in v19.4.0
type TLS struct {
CaCertificate string `protobuf:"bytes,1,opt,name=ca_certificate" json:"ca_certificate,omitempty"`
Certificate string `protobuf:"bytes,2,opt,name=certificate" json:"certificate,omitempty"`
Key string `protobuf:"bytes,3,opt,name=key" json:"key,omitempty"`
// contains filtered or unexported fields
}
func (*TLS) ClientCertificates ¶ added in v19.4.0
func (x *TLS) ClientCertificates() ([]tls.Certificate, error)
ClientCertificates returns the keypair the connection presents, or nil when there is none. Certificate and Key belong together, so one without the other is an error rather than silently no keypair.
func (*TLS) Descriptor
deprecated
added in
v19.4.0
func (*TLS) GetCaCertificate ¶ added in v19.4.0
func (*TLS) GetCertificate ¶ added in v19.4.0
func (*TLS) ProtoMessage ¶ added in v19.4.0
func (*TLS) ProtoMessage()
func (*TLS) ProtoReflect ¶ added in v19.4.0
func (x *TLS) ProtoReflect() protoreflect.Message