db

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package db is the only place that holds a connection to the database: a lazy, bounded pool and two transaction runners (read-only and read-write) that apply the session settings and clean up after every call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtLeast

func AtLeast(version string, major, minor int) bool

AtLeast reports whether an extension version of the form major.minor is at least major.minor; a version that cannot be read counts as older.

Types

type ConnectError

type ConnectError struct{ Err error }

ConnectError reports a failure to obtain a connection to the database.

func (*ConnectError) Error

func (e *ConnectError) Error() string

Error returns "cannot connect to the database: " followed by the driver message, which holds no password.

func (*ConnectError) Unwrap

func (e *ConnectError) Unwrap() error

Unwrap returns the driver error.

type DB

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

DB is the connection pool of the process and its transaction runners.

func New

func New(cfg *config.Config) (*DB, error)

New builds the pool. It opens no connection: the first one is opened by the first call.

func (*DB) Close

func (d *DB) Close()

Close closes the pool, waiting for the connections in use to be released.

func (*DB) Info

func (d *DB) Info(ctx context.Context) (Info, error)

Info returns the server version and installed extensions, fetched on first use and cached on success.

func (*DB) ReadOnly

func (d *DB) ReadOnly(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error

ReadOnly runs fn in a READ ONLY transaction that is always rolled back.

func (*DB) ReadWrite

func (d *DB) ReadWrite(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error

ReadWrite runs fn in a transaction that is committed when fn succeeds and rolled back otherwise. Tools call it only in unrestricted mode.

func (*DB) VectorTypes added in v0.4.0

func (d *DB) VectorTypes(ctx context.Context, t pgx.Tx) (map[uint32]bool, error)

VectorTypes returns the OIDs of pgvector's vector and halfvec types, empty without pgvector. A stale answer is read again through t, the caller's transaction, so that a fresh one costs no transaction of its own.

type Info

type Info struct {
	VersionNum int
	Extensions map[string]string // extname -> extversion
}

Info describes the server: its version and its installed extensions.

Jump to

Keyboard shortcuts

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