Skip to main content

GlobalAliasStorage

Struct GlobalAliasStorage 

Source
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

Source

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
Source

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).

Source

pub async fn alias_create( &self, scope: AliasScope, record: AliasRecord, ) -> Result<(), MiniAppError>

Insert a new alias into the specified scope’s storage.

§Errors
Source

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.

Source

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).

Source

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).

Source

pub async fn alias_delete( &self, scope: AliasScope, name: &str, ) -> Result<(), MiniAppError>

Delete an alias from a specific scope.

§Errors
Source

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

Trait Implementations§

Source§

impl Debug for GlobalAliasStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more