backend

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DBString to format connection string to database for postgres
	PostgresDBString = "host=%s port=%s dbname=%s user=%s password=%s sslmode=%s"
	// MySQLDBString to format connection string for MySQL
	MySQLDBString = "%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local"
	// DBKey to identify the configuration JSON key
	DBKey = "db"
	// Database types
	DBTypePostgres = "postgres"
	DBTypeMySQL    = "mysql"
	DBTypeSQLite   = "sqlite"
)

Variables

This section is empty.

Functions

func PrepareDSN

func PrepareDSN(config JSONConfigurationDB) string

PrepareDSN to generate DB connection string

Types

type DBManager

type DBManager struct {
	Conn   *gorm.DB
	Config *JSONConfigurationDB
	DSN    string
}

DBManager have access to backend

func CreateDBManager

func CreateDBManager(dbConfig JSONConfigurationDB) (*DBManager, error)

CreateDBManager to initialize the DB struct

func CreateDBManagerFile

func CreateDBManagerFile(file string) (*DBManager, error)

CreateDBManager to initialize the DB struct

func (*DBManager) Check

func (db *DBManager) Check() error

Check to verify if connection is open and ready

func (*DBManager) GetDB

func (db *DBManager) GetDB() (*gorm.DB, error)

GetDB to get DB using GORM based on the configured driver

type JSONConfigurationDB

type JSONConfigurationDB struct {
	Type            string `json:"type"` // Database type: postgres, mysql, sqlite
	Host            string `json:"host"`
	Port            string `json:"port"`
	Name            string `json:"name"`
	Username        string `json:"username"`
	Password        string `json:"password"`
	SSLMode         string `json:"sslmode"`
	MaxIdleConns    int    `json:"maxIdleConns"`
	MaxOpenConns    int    `json:"maxOpenConns"`
	ConnMaxLifetime int    `json:"connMaxLifetime"`
	ConnRetry       int    `json:"connRetry"`
	FilePath        string `json:"filePath"` // Used for SQLite
}

JSONConfigurationDB to hold all backend configuration values

func LoadConfiguration

func LoadConfiguration(file, key string) (JSONConfigurationDB, error)

LoadConfiguration to load the DB configuration file and assign to variables

Jump to

Keyboard shortcuts

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