db

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

README

Database management

This file briefly documents how the db package initializes the MariaDB connection and applies schema SQL included in the repository.

Paths

  • db/create.sql — embedded initial schema (creates all required tables).
  • db/upgrade.sql — embedded SQL file containing idempotent schema upgrades.

Environment variables (used to build DSN)

-- NETHVOICE_MIDDLEWARE_MARIADB_HOST (default: localhost) -- NETHVOICE_MIDDLEWARE_MARIADB_PORT (default: 3306) -- NETHVOICE_MIDDLEWARE_MARIADB_USER (default: root) -- NETHVOICE_MIDDLEWARE_MARIADB_PASSWORD (default: root in local/test) -- NETHVOICE_MIDDLEWARE_MARIADB_DATABASE (default: nethcti3)

Schema Migrations & Upgrades

If the database already exists when the application starts, db.Init() will run the embedded db/upgrade.sql automatically. The statements in upgrade.sql must be idempotent and safe to re-run.

Please note that db/upgrade.sql should contain idempotent statements (or checks) because it may be executed on existing databases and can be re-run in tests/CI.

Connection Pool Configuration

The middleware uses a connection pool with the following defaults:

  • Max open connections: 25
  • Max idle connections: 5
  • Connection max lifetime: 5 minutes

These can be adjusted in db/db.go if needed for your workload.

Testing

  • Unit tests for the package run with go test ./db.
  • Integration tests that exercise the real DB require a running MariaDB instance (see agents.md for a Podman/Docker command).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Access the database with GetDB() to ensure proper initialization and reconnection.
	DB *sql.DB
)

Functions

func Close

func Close() error

Close gracefully closes the database connection pool.

func GetDB

func GetDB() *sql.DB

func Init

func Init() error

Init initializes the database connection pool with the configured MariaDB settings. It performs health checks and creates necessary schema.

Types

This section is empty.

Jump to

Keyboard shortcuts

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