database

package
v0.1.0-alpha.17 Latest Latest
Warning

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

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

Documentation

Overview

Package database provides database connection and migration functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database represents a database connection with migration capabilities.

func New

func New(connection string) (*Database, error)

New creates a new Database instance with the given connection string.

func (*Database) Connection

func (db *Database) Connection() *sqlx.DB

Connection returns the underlying sqlx database connection.

func (*Database) Migrate

func (db *Database) Migrate(ctx context.Context) error

Migrate runs all pending migrations for registered repositories.

func (*Database) RegisterRepository

func (db *Database) RegisterRepository(name string, repository any)

RegisterRepository registers a repository in the database. If repository implements migrator interface, it will migrate when `Migrate` is called.

type Migration

type Migration struct {
	ID   string
	Up   string
	Down string
	// contains filtered or unexported fields
}

Migration represents a database migration with up and down SQL statements.

func ParseMigrations

func ParseMigrations(fsys fs.FS) ([]Migration, error)

ParseMigrations parses SQL migration files from an fs.FS. Files must have .sql extension and contain -- +migrate Up marker. The -- +migrate Down marker is optional. Migration ID is derived from the filename without extension. Migrations are returned sorted lexicographically by filename.

Jump to

Keyboard shortcuts

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