database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectGormDB

func ConnectGormDB(config *Config) (*gorm.DB, error)

ConnectGormDB establishes a GORM connection to the database (SQLite or PostgreSQL)

Types

type Config

type Config struct {
	// Database type (sqlite or postgres)
	Type DatabaseType

	// SQLite configuration
	DatabasePath string // Path to SQLite database file

	// PostgreSQL configuration
	Host     string
	Port     string
	Username string
	Password string
	Database string
	SSLMode  string

	// Connection pool settings (applies to both database types)
	MaxOpenConns    int           // Maximum number of open connections
	MaxIdleConns    int           // Maximum number of idle connections
	ConnMaxLifetime time.Duration // Maximum amount of time a connection may be reused
	ConnMaxIdleTime time.Duration // Maximum amount of time a connection may be idle before being closed
}

Config holds database connection configuration

func NewDatabaseConfig

func NewDatabaseConfig() *Config

NewDatabaseConfig creates a new database configuration from environment variables Supports both SQLite (default) and PostgreSQL databases Configuration priority:

  1. If DB_TYPE=postgres → PostgreSQL (DB_HOST, DB_PASSWORD, etc. required)
  2. If DB_TYPE=sqlite OR DB_PATH is set → File-based SQLite (default: ./data/audit.db) Note: Unknown DB_TYPE values also default to file-based SQLite
  3. If no database configuration (no DB_TYPE, no DB_PATH) → In-memory SQLite (:memory:) Note: DB_HOST is only relevant for PostgreSQL and does not count as "database configuration"

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database to use

const (
	DatabaseTypeSQLite   DatabaseType = "sqlite"
	DatabaseTypePostgres DatabaseType = "postgres"
)

Jump to

Keyboard shortcuts

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