db

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package db opens the selected persistent store, runs its embedded migrations, and wires the generated gorm/gen repositories' default query. Business code uses the typed repositories (internal/pkg/db/repositories) — never raw SQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver   Driver
	Hostname string
	Port     int
	Username string
	Password string
	Database string
	IsSSL    bool

	SQLitePath        string
	SQLiteBusyTimeout time.Duration
	// contains filtered or unexported fields
}

Config is the database connection config, mapped from the app config so the db package doesn't depend on the whole config struct.

type Driver

type Driver string

Driver identifies the persistence implementation selected for one Chatz process.

const (
	// DriverPostgres is the shared and scale-out persistence mode.
	DriverPostgres Driver = "postgres"

	// DriverSQLite is the single-process, local-volume persistence mode.
	DriverSQLite Driver = "sqlite"
)

type Handle

type Handle struct {
	GormDB *gorm.DB
	Driver Driver
	// contains filtered or unexported fields
}

Handle is an open database connection owned by its caller. The GORM handle backs the generated repositories; Close releases the underlying SQL pool.

func Connect

func Connect(ctx context.Context, cfg Config) (*Handle, error)

Connect opens the configured database, runs its migrations, and sets the generated repositories' default query. The returned handle is owned by the caller — Close it on shutdown.

func (*Handle) Close

func (h *Handle) Close() error

Close releases the database resources owned by the handle.

func (*Handle) MigrationStatus

func (h *Handle) MigrationStatus(ctx context.Context) (MigrationStatus, error)

MigrationStatus reads the actual migration ledger after startup migrations have completed. It is diagnostics-only and does not mutate the database.

func (*Handle) PostgreSQL

func (h *Handle) PostgreSQL() *postgresql.Postgresql

PostgreSQL returns the native connection for PostgreSQL-only maintenance operations, such as the migration reversibility integration test. It is nil for the SQLite driver; application code should use GormDB + repositories.

type MigrationStatus

type MigrationStatus struct {
	Version int
	Dirty   bool
}

MigrationStatus is the database's applied schema position.

Directories

Path Synopsis
Package migrations embeds the SQL migration files into the binary so the binary is self-contained (no directory to mount).
Package migrations embeds the SQL migration files into the binary so the binary is self-contained (no directory to mount).
Package models holds the plain Go structs that gorm/gen generates type-safe repositories from.
Package models holds the plain Go structs that gorm/gen generates type-safe repositories from.

Jump to

Keyboard shortcuts

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