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

storage

package
v0.0.0-...-6451a0a Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package storage opens a database for one service. It runs no migrations: each service's backend owns its own schema and migrates itself when it is wired up.

Index

Constants

View Source
const (
	DriverSQLite   = "sqlite"
	DriverPostgres = "postgres"
)

SQLite is the default because it needs nothing to be running.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, cfg Config, schema string) (*sql.DB, error)

Open opens the configured database. schema names the Postgres schema this service owns; SQLite ignores it.

Types

type Config

type Config struct {
	// Driver is DriverSQLite or DriverPostgres.
	Driver string
	// Path is the SQLite file. The postgres driver ignores it.
	Path string
	// DSN is the Postgres connection string. The sqlite driver ignores it.
	DSN string
	// MaxOpenConns bounds each Postgres pool. SQLite is always one connection.
	MaxOpenConns int
}

func Load

func Load() Config

func (Config) Validate

func (c Config) Validate() error

type Handle

type Handle struct {
	SQL *sql.DB
}

Handle is one service's open database.

func OpenHandle

func OpenHandle(ctx context.Context, cfg Config, schema string) (*Handle, error)

OpenHandle opens the configured database for the service owning schema.

func (*Handle) Close

func (h *Handle) Close() error

func (*Handle) Ping

func (h *Handle) Ping(ctx context.Context) error

Jump to

Keyboard shortcuts

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