database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package database holds database connection configuration and lifecycle.

Index

Constants

View Source
const (
	DriverPostgres = "postgres"
	DriverMySQL    = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver string `mapstructure:"driver"   validate:"required,oneof=postgres"`
	Test   bool   `mapstructure:"-"`
}

Config selects the database driver. Driver-specific settings live outside this struct so service config can keep database selection small and place driver config in sibling top-level blocks.

func (Config) Validate

func (c Config) Validate() error

type Database

type Database struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config, pg PostgresConfig) (*Database, *sql.DB, error)

func (*Database) DB

func (c *Database) DB() *sql.DB

func (*Database) Start

func (c *Database) Start(ctx context.Context, l logger.Logger, cfg Config) error

func (*Database) Stop

func (c *Database) Stop(l logger.Logger) error

type PostgresConfig

type PostgresConfig struct {
	Host          string `mapstructure:"host"`
	Port          int    `mapstructure:"port"`
	Name          string `mapstructure:"name"`
	Username      string `mapstructure:"username"`
	Password      string `mapstructure:"password"`
	Timeout       int    `mapstructure:"timeout"`
	SSLMode       string `mapstructure:"ssl_mode"`
	MigrationPath string `mapstructure:"migration_path"`
}

PostgresConfig holds PostgreSQL connection settings. Services embed it in their config structs; the mapstructure tags live here so every service shares the same config schema.

func (PostgresConfig) Validate

func (c PostgresConfig) Validate() error

Jump to

Keyboard shortcuts

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