query_flow/db.rs
1//! Database trait for query execution.
2
3use std::sync::Arc;
4
5use crate::asset::AssetKey;
6use crate::loading::AssetLoadingState;
7use crate::query::Query;
8use crate::QueryError;
9
10/// Database trait that provides query execution and asset access.
11///
12/// This trait is implemented by both [`QueryRuntime`](crate::QueryRuntime) and
13/// [`QueryContext`](crate::QueryContext), allowing queries to work with either.
14///
15/// - `QueryRuntime::query()` / `QueryRuntime::asset()`: No dependency tracking
16/// - `QueryContext::query()` / `QueryContext::asset()`: With dependency tracking
17pub trait Db {
18 /// Execute a query, returning the cached result if available.
19 fn query<Q: Query>(&self, query: Q) -> Result<Arc<Q::Output>, QueryError>;
20
21 /// Access an asset by key.
22 fn asset<K: AssetKey>(&self, key: K) -> Result<AssetLoadingState<K>, QueryError>;
23
24 /// List all executed queries of a specific type.
25 fn list_queries<Q: Query>(&self) -> Vec<Q>;
26
27 /// List all resolved asset keys of a specific type.
28 fn list_asset_keys<K: AssetKey>(&self) -> Vec<K>;
29}