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

database

package
v0.112.13 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAllEnv

func BindAllEnv(v *viper.Viper)

Types

type ConfigFile

type ConfigFile struct {
	PostgresHost     string `mapstructure:"host" json:"host,omitempty" default:"127.0.0.1"`
	PostgresPort     int    `mapstructure:"port" json:"port,omitempty" default:"5431"`
	PostgresUsername string `mapstructure:"username" json:"username,omitempty" default:"hatchet"`
	PostgresPassword string `mapstructure:"password" json:"password,omitempty" default:"hatchet"`
	PostgresDbName   string `mapstructure:"dbName" json:"dbName,omitempty" default:"hatchet"`
	PostgresSSLMode  string `mapstructure:"sslMode" json:"sslMode,omitempty" default:"disable"`

	ReadReplicaEnabled     bool   `mapstructure:"readReplicaEnabled" json:"readReplicaEnabled,omitempty" default:"false"`
	ReadReplicaDatabaseURL string `mapstructure:"readReplicaDatabaseUrl" json:"readReplicaDatabaseUrl,omitempty" default:""`
	ReadReplicaMaxConns    int    `mapstructure:"readReplicaMaxConns" json:"readReplicaMaxConns,omitempty" default:"50"`
	ReadReplicaMinConns    int    `mapstructure:"readReplicaMinConns" json:"readReplicaMinConns,omitempty" default:"10"`

	MaxConns int `mapstructure:"maxConns" json:"maxConns,omitempty" default:"50"`
	MinConns int `mapstructure:"minConns" json:"minConns,omitempty" default:"1"`

	// PgBouncerURL is an optional connection string for pgbouncer. When set, most queries are routed
	// through pgbouncer, other than DDL-modifying statements which use the separate direct connection pool.
	PgBouncerURL string `mapstructure:"pgbouncerUrl" json:"pgbouncerUrl,omitempty" default:""`

	DDLPoolMaxConns int `mapstructure:"ddlPoolMaxConns" json:"ddlPoolMaxConns,omitempty" default:"5"`
	DDLPoolMinConns int `mapstructure:"ddlPoolMinConns" json:"ddlPoolMinConns,omitempty" default:"1"`

	MaxConnLifetime time.Duration `mapstructure:"maxConnLifetime" json:"maxConnLifetime,omitempty" default:"15m"`
	MaxConnIdleTime time.Duration `mapstructure:"maxConnIdleTime" json:"maxConnIdleTime,omitempty" default:"1m"`

	// ApplicationNamePrefix is prepended to the pgx application_name as "<prefix>:<otel service name>"
	// so connections in pg_stat_activity can be attributed to a deployment. In Kubernetes this is
	// populated with the pod namespace via the downward API (K8S_POD_NAMESPACE).
	ApplicationNamePrefix string `mapstructure:"applicationNamePrefix" json:"applicationNamePrefix,omitempty" default:""`

	Seed SeedConfigFile `mapstructure:"seed" json:"seed,omitempty"`

	Logger shared.LoggerConfigFile `mapstructure:"logger" json:"logger,omitempty"`

	LogQueries bool `mapstructure:"logQueries" json:"logQueries,omitempty" default:"false"`

	CacheDuration time.Duration `mapstructure:"cacheDuration" json:"cacheDuration,omitempty" default:"5s"`

	// EnforceUTCTimezone enforces that the database instance timezone is set to UTC.
	// If enabled and the database timezone is not UTC, the server will panic on startup.
	// To disable this check, set DATABASE_ENFORCE_UTC_TIMEZONE=false
	EnforceUTCTimezone bool `mapstructure:"enforceUtcTimezone" json:"enforceUtcTimezone,omitempty" default:"true"`
}

type Layer

type Layer struct {
	Disconnect func() error

	Pool *pgxpool.Pool

	// DirectDatabaseURL is the resolved direct (non-pgbouncer) connection URL.
	// LISTEN/NOTIFY does not survive transaction pooling, so consumers that
	// need LISTEN (e.g. the postgres PubSub) must build their pools from this.
	DirectDatabaseURL string

	ReadReplicaPool *pgxpool.Pool

	// DDLPool is meant for DDL-modifying operations like DETACH PARTITION CONCURRENTLY, which
	// are critical and cannot run in an explicit transaction (and therefor cannot go through pgbouncer when it's configured)
	DDLPool *pgxpool.Pool

	V1 v1.Repository

	Seed SeedConfigFile

	// Logger is the configured database logger. Consumers should read it via
	// GetLogger, which falls back to a disabled logger when the layer was
	// constructed without one.
	Logger *zerolog.Logger
}

func (*Layer) GetLogger added in v0.106.11

func (l *Layer) GetLogger() *zerolog.Logger

GetLogger returns the layer's configured logger, or a disabled logger if the layer was constructed without one. Library code writing diagnostics should use this rather than printing to stdout/stderr directly, so that embedders keep control over the output.

type SeedConfigFile

type SeedConfigFile struct {
	AdminEmail    string `mapstructure:"adminEmail" json:"adminEmail,omitempty" default:"admin@example.com"`
	AdminPassword string `mapstructure:"adminPassword" json:"adminPassword,omitempty" default:"Admin123!!"`
	AdminName     string `mapstructure:"adminName" json:"adminName,omitempty" default:"Admin"`

	DefaultTenantName string `mapstructure:"defaultTenantName" json:"defaultTenantName,omitempty" default:"Default"`
	DefaultTenantSlug string `mapstructure:"defaultTenantSlug" json:"defaultTenantSlug,omitempty" default:"default"`
	DefaultTenantID   string `mapstructure:"defaultTenantId" json:"defaultTenantId,omitempty" default:"707d0855-80ab-4e1f-a156-f1c4546cbf52"`
}

Jump to

Keyboard shortcuts

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