Skip to main content

TableRegistry

Struct TableRegistry 

Source
pub struct TableRegistry { /* private fields */ }
Expand description

Registry of all mounted tables for the current server instance.

Build with TableRegistry::mount_from_dirs (multi-table) or TableRegistry::mount_legacy (single-table legacy mode). After construction the registry is immutable.

Implementations§

Source§

impl TableRegistry

Source

pub async fn mount_from_dirs( user_dir: Option<&Path>, project_dir: Option<&Path>, ) -> Result<Self, MiniAppError>

Mount tables discovered from the User-scope and Project-scope directories.

This is the crux #1 entry point. It performs a two-phase scan:

  1. Scan user_dir (base layer): every subdirectory <table>/ that contains both schema.yaml and <table>.db is mounted.
  2. Scan project_dir (override layer): same discovery, but any table name already present from the User scan is replaced (file-level swap, not field-level merge).

Either argument may be None (e.g. if the directory does not exist or was not configured). A non-existent directory is skipped with a tracing::warn!; it is not a fatal error.

§Arguments
  • user_dir: path to the User-scope directory (e.g. ~/.mini-app/). Subdirectories represent table names.
  • project_dir: path to the Project-scope directory (e.g. ./.mini-app/). Overrides same-named User tables.
§Returns

A TableRegistry with all discovered tables mounted and default_table = None (no default in multi-table mode).

§Errors

Returns MiniAppError::Io if a directory can be opened but read_dir or file reads fail. Missing directories are skipped, not treated as errors.

Source

pub async fn mount_legacy( schema_path: &Path, db_path: &Path, ) -> Result<Self, MiniAppError>

Mount a single legacy table from explicit schema_path and db_path.

This is the crux #2 entry point. It registers the table described by schema_path and sets default_table to that table’s name so callers can omit the table argument when using TableRegistry::resolve.

§Arguments
  • schema_path: path to the schema.yaml file.
  • db_path: path to the SQLite database file.
§Returns

A TableRegistry with a single table mounted and default_table = Some(<table_name>).

§Errors
Source

pub fn resolve(&self, name: Option<&str>) -> Result<&TableEntry, MiniAppError>

Resolve a table by name, falling back to default_table when name is None.

This is the crux #2 runtime entry point. When a single-table legacy env is set and default_table is Some, name = None is allowed and returns the default entry. In multi-table mode (default_table = None) name must be Some.

§Arguments
  • name: the requested table name, or None to use the default.
§Returns

A reference to the TableEntry for the resolved table.

§Errors
Source

pub fn default_table(&self) -> Option<&str>

Returns the default table name, if any.

Some when this registry was built via mount_legacy (single-table mode). None in multi-table mode.

§Returns

Some(&str) with the default table name, or None.

Source

pub fn table_count(&self) -> usize

Returns the number of tables currently mounted in the registry.

§Returns

The count of mounted tables.

Source

pub fn table_names(&self) -> impl Iterator<Item = &str>

Returns an iterator over all mounted table names.

The iteration order is not guaranteed.

§Returns

An iterator yielding &str table names.

Source

pub fn global_aliases(&self) -> Option<&Arc<GlobalAliasStorage>>

Returns the global alias storage handle if available.

Some when this registry was built via TableRegistry::mount_from_dirs with at least one of user_dir / project_dir populated (Phase 2 multi-table mode). None in legacy single-table mode and in test-only TableRegistry::from_entries / TableRegistry::from_single constructors.

Source

pub fn entries(&self) -> &HashMap<String, TableEntry>

Returns an immutable reference to the entries map.

Provides read-only access to all mounted TableEntry values, keyed by table name. This is used by rebuild_registry() to diff old and new registries, and by schema CRUD tools to look up an entry’s schema_path and store for backup / row-count operations.

No mutation API is exposed — the entries HashMap is always accessed via immutable reference so existing registry invariants are preserved.

Source

pub fn from_entries( entries: HashMap<String, TableEntry>, default_table: Option<String>, ) -> Self

Build a registry from a pre-constructed entry map and optional default.

This constructor is intended for use in tests where stores are created directly (e.g. in-memory SQLite) without going through the directory scan path.

§Arguments
  • entries: map of table names to TableEntry values.
  • default_table: optional default table name (set for legacy compat).
Source

pub fn from_single( store: Store, schema: SchemaConfig, schema_path: PathBuf, table_name: String, ) -> Self

Build a single-entry registry from a pre-opened Store and schema.

Sets default_table to table_name so callers can omit the table argument (crux #2 legacy adapter).

§Arguments
  • store: the already-opened Store.
  • schema: the parsed SchemaConfig.
  • schema_path: filesystem path to schema.yaml.
  • table_name: the name to register this table under and set as default.
Source

pub async fn mount_legacy_into( registry: TableRegistry, schema_path: &Path, db_path: &Path, ) -> Result<TableRegistry, MiniAppError>

Merge a legacy single-table configuration into an existing registry.

Loads the schema from schema_path, opens the SQLite database at db_path, and inserts the resulting entry into self. If the table name is already present in the registry it is replaced (legacy env takes precedence) and a tracing::warn! is emitted. Also sets default_table to the legacy table name so callers can omit the table argument (crux #2 legacy adapter).

§Arguments
  • registry: the registry to merge into (consumed and returned).
  • schema_path: path to the schema.yaml file.
  • db_path: path to the SQLite database file.
§Errors

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