database

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package database defines supported database engines and their container configurations for one-click local provisioning via devx db spawn.

Index

Constants

This section is empty.

Variables

View Source
var Registry = map[string]Engine{
	"postgres": {
		Name:         "PostgreSQL",
		Image:        "docker.io/library/postgres:16-alpine",
		DefaultPort:  5432,
		InternalPort: 5432,
		VolumePath:   "/var/lib/postgresql/data",
		Env: map[string]string{
			"POSTGRES_USER":     "devx",
			"POSTGRES_PASSWORD": "devx",
			"POSTGRES_DB":       "devx",
		},
		ReadyLog:      "database system is ready to accept connections",
		ConnStringFmt: "postgresql://%s:%s@localhost:%d/%s",
	},
	"redis": {
		Name:          "Redis",
		Image:         "docker.io/library/redis:7-alpine",
		DefaultPort:   6379,
		InternalPort:  6379,
		VolumePath:    "/data",
		Env:           map[string]string{},
		ReadyLog:      "Ready to accept connections",
		ConnStringFmt: "redis://localhost:%d",
	},
	"mysql": {
		Name:         "MySQL",
		Image:        "docker.io/library/mysql:8",
		DefaultPort:  3306,
		InternalPort: 3306,
		VolumePath:   "/var/lib/mysql",
		Env: map[string]string{
			"MYSQL_ROOT_PASSWORD": "devx",
			"MYSQL_DATABASE":      "devx",
			"MYSQL_USER":          "devx",
			"MYSQL_PASSWORD":      "devx",
		},
		ReadyLog:      "ready for connections",
		ConnStringFmt: "mysql://%s:%s@localhost:%d/%s",
	},
	"mongo": {
		Name:         "MongoDB",
		Image:        "docker.io/library/mongo:7",
		DefaultPort:  27017,
		InternalPort: 27017,
		VolumePath:   "/data/db",
		Env: map[string]string{
			"MONGO_INITDB_ROOT_USERNAME": "devx",
			"MONGO_INITDB_ROOT_PASSWORD": "devx",
		},
		ReadyLog:      "Waiting for connections",
		ConnStringFmt: "mongodb://%s:%s@localhost:%d",
	},
}

Registry of all supported database engines.

Functions

func DeleteSnapshot added in v0.18.0

func DeleteSnapshot(engine, snapshotName string) error

DeleteSnapshot removes a snapshot's tar and metadata files.

func RestoreSnapshot added in v0.18.0

func RestoreSnapshot(runtime, engine, snapshotName string) error

RestoreSnapshot stops the running container, replaces the volume with the snapshot contents, and restarts the container.

func SnapshotDir added in v0.18.0

func SnapshotDir() string

SnapshotDir returns the directory where snapshots are stored.

func SupportedEngines

func SupportedEngines() []string

SupportedEngines returns a sorted list of engine names.

Types

type Engine

type Engine struct {
	Name          string            // Human-readable name
	Image         string            // Container image
	DefaultPort   int               // Default port on the host
	InternalPort  int               // Port inside the container
	VolumePath    string            // Data directory inside the container
	Env           map[string]string // Default environment variables
	ReadyLog      string            // Log line that indicates the DB is ready
	ConnStringFmt string            // printf format for the connection string: host, port, user, pass, dbname
}

Engine holds the container configuration for a database engine.

func (Engine) ConnString

func (e Engine) ConnString(port int) string

ConnString returns the formatted connection string for a given engine.

type SnapshotMeta added in v0.18.0

type SnapshotMeta struct {
	Name      string    `json:"name"`
	Engine    string    `json:"engine"`
	Volume    string    `json:"volume"`
	CreatedAt time.Time `json:"created_at"`
	SizeBytes int64     `json:"size_bytes"`
}

SnapshotMeta holds metadata about a database snapshot.

func CreateSnapshot added in v0.18.0

func CreateSnapshot(runtime, engine, snapshotName string) (*SnapshotMeta, error)

CreateSnapshot exports the named volume for the given engine into a tar archive. It uses the 'runtime' binary (podman or docker).

func ListSnapshots added in v0.18.0

func ListSnapshots(engine string) ([]SnapshotMeta, error)

ListSnapshots returns all snapshots for a given engine.

Jump to

Keyboard shortcuts

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