database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sqlx.DB
	Logger *slog.Logger
}

DB wraps *sqlx.DB with app-specific helpers.

func New

func New(cfg *config.DatabaseConfig, logger *slog.Logger) (*DB, error)

New opens (or creates) the SQLite database at the path specified in cfg. The path is resolved relative to the running binary's directory so the database file always sits next to the executable.

func (*DB) Close

func (db *DB) Close() error

Close closes the underlying database connection.

func (*DB) Migrate

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

Migrate applies all pending goose migrations embedded in the migrations package. Safe to call on every startup — already-applied migrations are skipped automatically.

func (*DB) PluckHashes

func (db *DB) PluckHashes(ctx context.Context, table, keyCol, hashCol string) (map[int32]string, error)

PluckHashes returns column[keyCol] -> column[hashCol] for every row of table. Used for cheap change-detection passes (e.g. beatmap_id -> md5_hash) without pulling full rows into memory.

func (*DB) UpsertBatch

func (db *DB) UpsertBatch(ctx context.Context, table string, conflictCols []string, rows any) error

UpsertBatch writes rows (must be a slice of a struct with `db` tags, e.g. []model.Beatmap) into table in chunks sized to stay under sqliteMaxVariableNumber, all inside one transaction. conflictCols are the PK/unique columns used for ON CONFLICT ... DO UPDATE.

err := db.UpsertBatch(ctx, "beatmaps", []string{"beatmap_id"}, beatmaps)

Jump to

Keyboard shortcuts

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