database

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the global database instance

Functions

func Close

func Close() error

Close closes the database connection gracefully

func Connect

func Connect(cfg Config) error

Connect establishes a connection to the database with retry logic

func Health

func Health() error

Health checks the database connection health

func NewTestDB

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

NewTestDB creates an in-memory SQLite database for testing. Callers that need a users table should prefer SetupTestDB(t) which also creates the table and registers cleanup. This function is kept for compatibility with test helpers that manage their own schema.

func RollbackMigration

func RollbackMigration(db *gorm.DB, migrationsPath string) error

RollbackMigration rolls back the last migration

func RunMigrations

func RunMigrations(db *gorm.DB, migrationsPath string) error

RunMigrations runs all pending database migrations

func SetupTestDB

func SetupTestDB(t *testing.T) *gorm.DB

SetupTestDB creates an isolated in-memory SQLite database for a single test, creates the users table, and registers a cleanup function that closes the connection when the test finishes.

Types

type Config

type Config struct {
	URL          string
	MaxOpenConns int
	MaxIdleConns int
	ConnMaxLife  string
	LogLevel     string
}

Config holds database configuration

Jump to

Keyboard shortcuts

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