database

package
v1.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package database connects to Postgres or SQLite via Bun, with dialect auto-detection and optional tracing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBun

func NewBun(dsn string, opts ...Option) (*bun.DB, error)

NewBun opens a Bun database, choosing the dialect from the DSN scheme, applies pool options, and (unless WithoutPing) verifies the connection with a ping.

Types

type Option

type Option func(*config)

Option configures the database connection.

func WithConnMaxLifetime

func WithConnMaxLifetime(d time.Duration) Option

WithConnMaxLifetime sets the maximum amount of time a connection may be reused.

func WithMaxIdleConns

func WithMaxIdleConns(n int) Option

WithMaxIdleConns sets the maximum number of idle connections in the pool.

func WithMaxOpenConns

func WithMaxOpenConns(n int) Option

WithMaxOpenConns sets the maximum number of open connections to the database.

func WithPingTimeout

func WithPingTimeout(d time.Duration) Option

WithPingTimeout sets the timeout for the connect-time ping (default 5 s).

func WithTracing

func WithTracing() Option

WithTracing installs Bun's OpenTelemetry query hook so each query is recorded as a span on the active trace. It requires a configured tracer provider (see the tracing package's Setup); without one, spans are dropped.

func WithoutPing

func WithoutPing() Option

WithoutPing skips the connect-time ping.

Jump to

Keyboard shortcuts

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