pub struct AppState {
pub db: Arc<dyn DatabaseBackend>,
pub dialect: Arc<dyn SqlDialect>,
pub config: Arc<ArcSwap<AppConfig>>,
pub schema_cache: Arc<ArcSwap<Option<SchemaCache>>>,
pub auth: AuthState,
pub jwt_cache: JwtCache,
pub db_version: DbVersion,
pub pg_version: PgVersion,
}Expand description
Central application state.
Constructed once at startup and shared across all handlers.
The config and schema_cache fields use ArcSwap for
lock-free reads and atomic replacement during live reload.
Fields§
§db: Arc<dyn DatabaseBackend>Database backend (connection pool + execution + introspection).
dialect: Arc<dyn SqlDialect>SQL dialect for the active backend.
config: Arc<ArcSwap<AppConfig>>Atomically swappable configuration.
schema_cache: Arc<ArcSwap<Option<SchemaCache>>>Atomically swappable schema cache.
auth: AuthStateAuthentication state (JWT cache + config reference).
jwt_cache: JwtCacheJWT validation cache (shared with AuthState).
db_version: DbVersionDatabase version.
pg_version: PgVersionPostgreSQL version (legacy — prefer db_version field).
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new_with_backend(
db: Arc<dyn DatabaseBackend>,
dialect: Arc<dyn SqlDialect>,
config: AppConfig,
db_version: DbVersion,
) -> Self
pub fn new_with_backend( db: Arc<dyn DatabaseBackend>, dialect: Arc<dyn SqlDialect>, config: AppConfig, db_version: DbVersion, ) -> Self
Create a new AppState from a database backend, dialect, config, and version.
The schema cache starts as None — call Self::reload_schema_cache
after construction.
Sourcepub fn schema_cache_guard(&self) -> Guard<Arc<Option<SchemaCache>>>
pub fn schema_cache_guard(&self) -> Guard<Arc<Option<SchemaCache>>>
Get the current schema cache (may be None if not loaded).
Sourcepub async fn reload_config(&self) -> Result<(), Error>
pub async fn reload_config(&self) -> Result<(), Error>
Reload configuration from file and environment.
Sourcepub async fn reload_schema_cache(&self) -> Result<(), Error>
pub async fn reload_schema_cache(&self) -> Result<(), Error>
Load or reload the schema cache from the database.