Skip to main content

Module alias_storage

Module alias_storage 

Source
Expand description

Global alias storage (Phase 2). Persists named queries that span Single / Multi / Pattern table sources in a dedicated <project_dir or user_dir>/_global.db SQLite file, separate from per-table <table>.db. Provides lookup with Project → User precedence and a lossless migration helper from legacy per-table _aliases storage. Global alias storage — single-source-of-truth for named queries that span [SourceSpec::Single] / [SourceSpec::Multi] / [SourceSpec::Pattern] table sources.

§Phase 2 Storage Layout

  • Project scope: <project_dir>/_global.db (created on demand)
  • User scope: <user_dir>/_global.db (created on demand)
  • Lookup precedence: Project → User. A Project alias with the same name overrides the User alias of the same name.
  • Both scopes are independent SQLite files sharing the [CREATE_GLOBAL_ALIASES_SQL] schema.

_global.db is intentionally separate from per-table <table>.db files so that:

  1. one alias can reference multiple tables (Multi / Pattern sources) without owning a per-table SoT;
  2. user-wide BP aliases survive project deletion;
  3. project-specific aliases override user defaults transparently.

§Migration from Per-Table _aliases

[GlobalAliasStorage::migrate_from_per_table] performs a lossless, idempotent transfer of legacy 5-field rows from per-table _aliases into the project-scope _global_aliases, with sources filled in as Single(<table_name>) and aggregator = None. Rows already present in project storage are skipped (INSERT OR IGNORE semantics) so the migration may safely run on every registry open.

See crates/core/src/aggregator.rs for the [SourceSpec] / [AliasAggregator] primitives this storage persists.

Structs§

AliasRecord
A single global alias record.
GlobalAliasStorage
Global alias storage handle. Holds at most two SQLite connections (project + user), both wrapped in Arc<Mutex<_>> so the spawn_blocking body can lock + execute without violating Send / Sync bounds (rusqlite::Connection is !Send).

Enums§

AliasScope
Scope determines which _global.db (project or user) is written to. Lookup (alias_get / alias_list) always reads both with project taking precedence on name collisions.

Constants§

LEGACY_PER_TABLE_ALIASES_SQL
Per-table legacy DDL — exposed for migration sites that re-create the _aliases table on a fresh connection in tests.