pub struct GlobalAliasStorage { /* private fields */ }Expand description
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).
Implementations§
Source§impl GlobalAliasStorage
impl GlobalAliasStorage
Sourcepub fn open(
project_dir: Option<&Path>,
user_dir: Option<&Path>,
) -> Result<Self, MiniAppError>
pub fn open( project_dir: Option<&Path>, user_dir: Option<&Path>, ) -> Result<Self, MiniAppError>
Open both project and user _global.db files. Either argument may
be None (scope skipped). At least one MUST be Some, otherwise
the resulting storage has nothing to read or write.
Each provided directory is created on demand. The _global.db
file is created with the [CREATE_GLOBAL_ALIASES_SQL] schema if
absent. Existing files are opened as-is (no DDL migration).
§Errors
MiniAppError::Configwhen both arguments areNone.MiniAppError::Iowhen directory creation fails.MiniAppError::Storagewhen SQLite open / DDL execute fails.
Sourcepub fn path_for_scope(&self, scope: AliasScope) -> Option<&Path>
pub fn path_for_scope(&self, scope: AliasScope) -> Option<&Path>
Returns the resolved _global.db path for a scope, or None if
that scope is unmounted (or the storage was opened in-memory).
Sourcepub async fn alias_create(
&self,
scope: AliasScope,
record: AliasRecord,
) -> Result<(), MiniAppError>
pub async fn alias_create( &self, scope: AliasScope, record: AliasRecord, ) -> Result<(), MiniAppError>
Insert a new alias into the specified scope’s storage.
§Errors
MiniAppError::AliasAlreadyExistswhen an alias with the samenamealready exists in that scope (cross-scope collisions are permitted — project overrides user at lookup time).MiniAppError::Configwhen the scope is unmounted.MiniAppError::Storageon rusqlite failure.
Sourcepub async fn alias_get(&self, name: &str) -> Result<AliasRecord, MiniAppError>
pub async fn alias_get(&self, name: &str) -> Result<AliasRecord, MiniAppError>
Get an alias by name. Project storage is consulted first; on miss
the user storage is consulted. Returns MiniAppError::AliasNotFound
when neither scope has the alias.
Sourcepub async fn alias_get_scope(
&self,
scope: AliasScope,
name: &str,
) -> Result<Option<AliasRecord>, MiniAppError>
pub async fn alias_get_scope( &self, scope: AliasScope, name: &str, ) -> Result<Option<AliasRecord>, MiniAppError>
Get an alias from a specific scope. Returns Ok(None) when the
alias is absent (so the merged Self::alias_get can fall back
to the next scope without distinguishing missing scope from
missing row).
Sourcepub async fn alias_list(&self) -> Result<Vec<AliasRecord>, MiniAppError>
pub async fn alias_list(&self) -> Result<Vec<AliasRecord>, MiniAppError>
List all aliases across both scopes, sorted ascending by name. On name collision the Project entry is retained; the User entry is silently discarded (precedence rule).
Sourcepub async fn alias_delete(
&self,
scope: AliasScope,
name: &str,
) -> Result<(), MiniAppError>
pub async fn alias_delete( &self, scope: AliasScope, name: &str, ) -> Result<(), MiniAppError>
Delete an alias from a specific scope.
§Errors
MiniAppError::AliasNotFoundwhen the alias is absent in that scope.MiniAppError::Configwhen the scope is unmounted.MiniAppError::Storageon rusqlite failure.
Sourcepub async fn migrate_from_per_table(
&self,
target_scope: AliasScope,
per_table: Vec<(String, Arc<Mutex<Connection>>)>,
) -> Result<usize, MiniAppError>
pub async fn migrate_from_per_table( &self, target_scope: AliasScope, per_table: Vec<(String, Arc<Mutex<Connection>>)>, ) -> Result<usize, MiniAppError>
Lossless, idempotent migration of legacy per-table _aliases rows
into a chosen scope’s _global_aliases.
For each (table_name, per_table_conn) pair, every row from
the per-table _aliases table is loaded and inserted into
target_scope storage with sources = Single(<table_name>) and
aggregator = None. Rows whose name already exists in that
scope are skipped (INSERT OR IGNORE), so the migration may
safely run on every registry open.
Returns the number of rows newly written (skipped collisions are not counted).
§Errors
MiniAppError::Configwhentarget_scopeis unmounted.MiniAppError::Storageon rusqlite failure (per-table read or destination insert).