store

package
v0.1.0-alpha.78 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: GPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store owns MagicHandy's embedded SQLite datastore, schema migrations, transaction helpers, and legacy JSON import bookkeeping.

Index

Constants

View Source
const (
	ChatCursorLimit     = 4096
	ChatCursorRetention = 24 * time.Hour
)

ChatCursorLimit caps stored read markers. ChatCursorRetention governs normal reads and advancement; migration preserves legacy markers within the cap.

View Source
const (
	MediaTitleMaxRunes = 200
	MediaNotesMaxRunes = 2000
	MediaTagMaxRunes   = 40
)

Curation bounds shared by the migration checks and the media domain.

View Source
const (
	// DatabaseFileName is the single app datastore under the resolved data dir.
	DatabaseFileName = "magichandy.db"

	// CurrentSchemaVersion is mirrored into PRAGMA user_version.
	CurrentSchemaVersion = 31

	// LegacyStatusAbsent records that a legacy JSON file was not present.
	LegacyStatusAbsent = "absent"
	// LegacyStatusImported records that a legacy JSON file imported successfully.
	LegacyStatusImported = "imported"
	// LegacyStatusRecovered records that a legacy JSON file was unreadable or corrupt.
	LegacyStatusRecovered = "recovered"
	// LegacyStatusSkipped records that import was intentionally skipped.
	LegacyStatusSkipped = "skipped"
)
View Source
const AuditRowLimit = 10000

AuditRowLimit bounds durable history independently of the number of accounts or control requests. Domain writes share this cap through an insert trigger.

Variables

View Source
var ErrCorruptDatastore = errors.New("sqlite datastore is corrupt")

ErrCorruptDatastore classifies physical SQLite corruption that can be quarantined without interpreting or deleting the original bytes.

View Source
var ErrInvalidSchema = errors.New("sqlite schema is invalid")

ErrInvalidSchema reports a logically invalid schema that must not be replaced automatically because its rows may still be recoverable.

View Source
var ErrNewerSchema = errors.New("sqlite schema is newer than this binary")

ErrNewerSchema reports a DB created by a newer MagicHandy binary.

Functions

func ArchiveLegacyJSON

func ArchiveLegacyJSON(path string) (string, error)

ArchiveLegacyJSON renames a successfully imported JSON file without deleting its contents. If the archive name already exists, the original is left alone.

func MediaTagKey

func MediaTagKey(tag string) string

MediaTagKey uses the same Unicode normalization for deduplication and SQL lookup. SQLite's built-in NOCASE collation only folds ASCII letters.

func RecordLegacyImportTx

func RecordLegacyImportTx(ctx context.Context, tx *sql.Tx, status LegacyImportStatus) error

RecordLegacyImportTx records a one-time import status inside an existing tx.

Types

type DB

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

DB wraps the process-owned SQLite connection and schema helpers.

func Open

func Open(dataDir string) (*DB, error)

Open opens the MagicHandy SQLite datastore and applies migrations.

func (*DB) Close

func (db *DB) Close() error

Close releases the database handle.

func (*DB) DataDir

func (db *DB) DataDir() string

DataDir returns the resolved app data directory.

func (*DB) LegacyImportStatus

func (db *DB) LegacyImportStatus(ctx context.Context, domain string) (LegacyImportStatus, bool, error)

LegacyImportStatus returns the recorded import state for a legacy JSON file.

func (*DB) Path

func (db *DB) Path() string

Path returns the SQLite database file path.

func (*DB) RecordLegacyImport

func (db *DB) RecordLegacyImport(ctx context.Context, status LegacyImportStatus) error

RecordLegacyImport records a one-time import status.

func (*DB) Recovery

func (db *DB) Recovery() RecoveryStatus

Recovery reports whether Open quarantined a physically corrupt datastore and created a new one for this process.

func (*DB) SQL

func (db *DB) SQL() *sql.DB

SQL exposes the underlying handle for package-owned reads. Production writes must use WithTx so every logical domain shares the serialized writer.

func (*DB) WithTx

func (db *DB) WithTx(ctx context.Context, fn func(*sql.Tx) error) error

WithTx runs fn in one serialized SQL transaction. Waiting for the writer is cancellable, and a canceled waiter never invokes fn. Callers choose the lifetime: request contexts for cancelable work, process/durable contexts for accepted commits that must survive an HTTP disconnect.

type LegacyImportStatus

type LegacyImportStatus struct {
	Domain       string
	SourcePath   string
	ArchivedPath string
	Status       string
	Message      string
	ImportedAt   string
}

LegacyImportStatus records one legacy JSON import attempt.

type RecoveryStatus

type RecoveryStatus struct {
	Recovered bool
	BackupDir string
	Message   string
}

RecoveryStatus describes a non-destructive physical-corruption recovery.

Jump to

Keyboard shortcuts

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