database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

config.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB() *gorm.DB

DB returns the global database instance

func Default

func Default() (*gorm.DB, error)

Default returns the global instance, initializing if needed with error handling

func Init

func Init(configs ...Config) error

func InitFromEnv

func InitFromEnv() error

InitFromEnv initializes the global instance from environment variables (convenience method)

func New

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

New creates a new database instance with given config

func NewFromEnv

func NewFromEnv() (*gorm.DB, error)

NewFromEnv creates instance from environment variables (convenience constructor)

func Reset

func Reset()

Reset clears the global instance (for testing)

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown gracefully closes database connections

Types

type Config

type Config struct {
	Driver          string `env:"BEAVER_DB_DRIVER,default:sqlite"`
	Host            string `env:"BEAVER_DB_HOST,default:localhost"`
	Port            string `env:"BEAVER_DB_PORT"`
	Database        string `env:"BEAVER_DB_DATABASE,default:beaver.db"`
	Username        string `env:"BEAVER_DB_USERNAME"`
	Password        string `env:"BEAVER_DB_PASSWORD"`
	URL             string `env:"BEAVER_DB_URL"`
	AuthToken       string `env:"BEAVER_DB_AUTH_TOKEN"`
	MaxOpenConns    int    `env:"BEAVER_DB_MAX_OPEN_CONNS,default:25"`
	MaxIdleConns    int    `env:"BEAVER_DB_MAX_IDLE_CONNS,default:5"`
	ConnMaxLifetime int    `env:"BEAVER_DB_CONN_MAX_LIFETIME"`
	SSLMode         string `env:"BEAVER_DB_SSL_MODE,default:disable"`
}

func GetConfig

func GetConfig() (*Config, error)

GetConfig returns config loaded from environment

Jump to

Keyboard shortcuts

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