Help us shape the future of Go! Take the 2026 Go Developer Survey

databases

package
v0.0.12 Latest Latest
Warning

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

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

Documentation

Overview

Package databases provides database flake template registry and configuration.

Index

Constants

This section is empty.

Variables

View Source
var Registry = map[DatabaseType]DatabaseTemplate{
	DatabaseTypePostgres: {
		Type:              DatabaseTypePostgres,
		DisplayName:       "PostgreSQL",
		Description:       "Advanced open-source relational database",
		DefaultVersion:    "16",
		AvailableVersions: []string{"14", "15", "16", "17"},
		TemplateName:      "postgres.nix",
		DefaultPort:       5432,
		ConfigOptions: []ConfigOption{
			{Name: "storage_size", Type: "string", Default: "10Gi", Description: "Storage size for database data"},
			{Name: "max_connections", Type: "int", Default: "100", Description: "Maximum number of connections"},
			{Name: "shared_buffers", Type: "string", Default: "128MB", Description: "Shared buffer memory"},
			{Name: "backup_schedule", Type: "string", Default: "0 2 * * *", Description: "Cron schedule for backups"},
		},
	},
	DatabaseTypeMySQL: {
		Type:              DatabaseTypeMySQL,
		DisplayName:       "MySQL",
		Description:       "Popular open-source relational database",
		DefaultVersion:    "8.0",
		AvailableVersions: []string{"5.7", "8.0", "8.4"},
		TemplateName:      "mysql.nix",
		DefaultPort:       3306,
		ConfigOptions: []ConfigOption{
			{Name: "storage_size", Type: "string", Default: "10Gi", Description: "Storage size for database data"},
			{Name: "innodb_buffer_pool_size", Type: "string", Default: "128M", Description: "InnoDB buffer pool size"},
			{Name: "max_connections", Type: "int", Default: "151", Description: "Maximum number of connections"},
			{Name: "backup_schedule", Type: "string", Default: "0 2 * * *", Description: "Cron schedule for backups"},
		},
	},
	DatabaseTypeMariaDB: {
		Type:              DatabaseTypeMariaDB,
		DisplayName:       "MariaDB",
		Description:       "Community-developed fork of MySQL",
		DefaultVersion:    "11",
		AvailableVersions: []string{"10.6", "10.11", "11"},
		TemplateName:      "mariadb.nix",
		DefaultPort:       3306,
		ConfigOptions: []ConfigOption{
			{Name: "storage_size", Type: "string", Default: "10Gi", Description: "Storage size for database data"},
			{Name: "innodb_buffer_pool_size", Type: "string", Default: "128M", Description: "InnoDB buffer pool size"},
			{Name: "max_connections", Type: "int", Default: "151", Description: "Maximum number of connections"},
			{Name: "backup_schedule", Type: "string", Default: "0 2 * * *", Description: "Cron schedule for backups"},
		},
	},
	DatabaseTypeMongoDB: {
		Type:              DatabaseTypeMongoDB,
		DisplayName:       "MongoDB",
		Description:       "Document-oriented NoSQL database",
		DefaultVersion:    "7.0",
		AvailableVersions: []string{"6.0", "7.0"},
		TemplateName:      "mongodb.nix",
		DefaultPort:       27017,
		ConfigOptions: []ConfigOption{
			{Name: "storage_size", Type: "string", Default: "10Gi", Description: "Storage size for database data"},
			{Name: "wired_tiger_cache_size", Type: "string", Default: "256M", Description: "WiredTiger cache size"},
			{Name: "backup_schedule", Type: "string", Default: "0 2 * * *", Description: "Cron schedule for backups"},
		},
	},
	DatabaseTypeRedis: {
		Type:              DatabaseTypeRedis,
		DisplayName:       "Redis",
		Description:       "In-memory data structure store",
		DefaultVersion:    "7",
		AvailableVersions: []string{"6", "7"},
		TemplateName:      "redis.nix",
		DefaultPort:       6379,
		ConfigOptions: []ConfigOption{
			{Name: "maxmemory", Type: "string", Default: "256mb", Description: "Maximum memory limit"},
			{Name: "maxmemory_policy", Type: "string", Default: "allkeys-lru", Description: "Eviction policy when maxmemory is reached"},
			{Name: "appendonly", Type: "bool", Default: "yes", Description: "Enable append-only file persistence"},
			{Name: "backup_schedule", Type: "string", Default: "0 2 * * *", Description: "Cron schedule for backups"},
		},
	},
}

Registry contains all database templates indexed by type.

Functions

func GetBuildType

func GetBuildType() models.BuildType

GetBuildType returns the build type for database services. Database services always use pure-nix build type, never OCI. **Validates: Requirements 11.2**

func GetDefaultConfig

func GetDefaultConfig(dbType DatabaseType) map[string]string

GetDefaultConfig returns a map of default configuration values for a database type.

func GetDefaultPort

func GetDefaultPort(dbType DatabaseType) int

GetDefaultPort returns the default port for a database type.

func GetDefaultVersion

func GetDefaultVersion(dbType DatabaseType) string

GetDefaultVersion returns the default version for a database type.

func GetTemplateName

func GetTemplateName(dbType DatabaseType) string

GetTemplateName returns the Nix template name for a database type.

func IsValidVersion

func IsValidVersion(dbType DatabaseType, version string) bool

IsValidVersion checks if a version is valid for a database type.

Types

type ConfigOption

type ConfigOption struct {
	Name        string `json:"name"`
	Type        string `json:"type"` // string, int, bool
	Default     string `json:"default"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

ConfigOption defines a configuration option for a database template.

func GetConfigOptions

func GetConfigOptions(dbType DatabaseType) []ConfigOption

GetConfigOptions returns the configuration options for a database type.

type DatabaseCredentials

type DatabaseCredentials struct {
	Username     string `json:"username"`
	Password     string `json:"password"`
	DatabaseName string `json:"database_name"`
	Host         string `json:"host"`
	Port         int    `json:"port"`
	RootPassword string `json:"root_password,omitempty"` // For MySQL/MariaDB/MongoDB
}

DatabaseCredentials contains generated credentials for a database service.

func GenerateCredentials

func GenerateCredentials(dbType DatabaseType, serviceName string) (*DatabaseCredentials, error)

GenerateCredentials generates connection credentials for a database service. **Validates: Requirements 11.9**

func (*DatabaseCredentials) GetConnectionURL

func (c *DatabaseCredentials) GetConnectionURL(dbType DatabaseType) string

GetConnectionURL returns the connection URL for a database.

func (*DatabaseCredentials) GetSecretKeys

func (c *DatabaseCredentials) GetSecretKeys(dbType DatabaseType, serviceName string) map[string]string

GetSecretKeys returns the secret keys that should be stored for this database.

type DatabaseTemplate

type DatabaseTemplate struct {
	Type              DatabaseType   `json:"type"`
	DisplayName       string         `json:"display_name"`
	Description       string         `json:"description"`
	DefaultVersion    string         `json:"default_version"`
	AvailableVersions []string       `json:"available_versions"`
	TemplateName      string         `json:"template_name"` // Name of the .nix.tmpl file
	ConfigOptions     []ConfigOption `json:"config_options"`
	DefaultPort       int            `json:"default_port"`
}

DatabaseTemplate defines a database flake template configuration.

func GetTemplate

func GetTemplate(dbType DatabaseType) (*DatabaseTemplate, error)

GetTemplate returns the database template for a given type.

func GetTemplateByString

func GetTemplateByString(dbType string) (*DatabaseTemplate, error)

GetTemplateByString returns the database template for a given type string.

type DatabaseTemplateData

type DatabaseTemplateData struct {
	AppName         string
	ServiceName     string
	DatabaseType    DatabaseType
	DatabaseVersion string
	System          string
	Config          map[string]string
}

DatabaseTemplateData contains data for rendering database templates.

func NewDatabaseTemplateData

func NewDatabaseTemplateData(appName, serviceName string, dbType DatabaseType, version string) *DatabaseTemplateData

NewDatabaseTemplateData creates a new DatabaseTemplateData with defaults.

func (*DatabaseTemplateData) WithConfig

func (d *DatabaseTemplateData) WithConfig(config map[string]string) *DatabaseTemplateData

WithConfig sets custom configuration values.

type DatabaseType

type DatabaseType string

DatabaseType represents a supported database type.

const (
	DatabaseTypePostgres DatabaseType = "postgres"
	DatabaseTypeMySQL    DatabaseType = "mysql"
	DatabaseTypeMariaDB  DatabaseType = "mariadb"
	DatabaseTypeMongoDB  DatabaseType = "mongodb"
	DatabaseTypeRedis    DatabaseType = "redis"
)

func ValidDatabaseTypes

func ValidDatabaseTypes() []DatabaseType

ValidDatabaseTypes returns all valid database types.

func (DatabaseType) IsValid

func (t DatabaseType) IsValid() bool

IsValid checks if the database type is valid.

Jump to

Keyboard shortcuts

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