pub struct ResolvedModel {
pub entities: Vec<ResolvedEntity>,
pub entity_by_path: HashMap<String, ResolvedEntity>,
}Fields§
§entities: Vec<ResolvedEntity>§entity_by_path: HashMap<String, ResolvedEntity>Implementations§
Source§impl ResolvedModel
impl ResolvedModel
pub fn entity_by_path(&self, path: &str) -> Option<&ResolvedEntity>
Sourcepub fn with_package_id(self, package_id: &str) -> Self
pub fn with_package_id(self, package_id: &str) -> Self
Backfill package_id on all contained entities. Call this after resolve() when the
package id is known (e.g. from manifest.id or the route parameter).
Examples found in repository?
examples/server.rs (line 61)
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18 dotenvy::dotenv().ok();
19 let filter =
20 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("architect_sdk=info"));
21 tracing_subscriber::fmt().with_env_filter(filter).init();
22
23 let database_url =
24 std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite://architect.db".into());
25 ensure_database_exists(&database_url).await?;
26
27 // create_pool uses the compiled-in dialect automatically (sqlite by default).
28 let pool = create_pool(&database_url, 5).await?;
29
30 let dialect = architect_sdk::db::active_dialect();
31 ensure_sys_tables(&pool, dialect.as_ref()).await?;
32
33 let tenant_registry = load_registry_from_pool(&pool)
34 .await
35 .map_err(|e| -> Box<dyn std::error::Error> { Box::new(e) })?;
36 tracing::info!("loaded tenant registry (X-Tenant-ID required for config and entity APIs)");
37
38 let (config, package_id) = match std::env::var("PACKAGE_PATH") {
39 Ok(package_path) => {
40 tracing::info!("loading config from package path: {}", package_path);
41 let (cfg, id) = load_config_from_package_path(&package_path).await?;
42 (cfg, id)
43 }
44 Err(_) => {
45 tracing::info!("PACKAGE_PATH not set; loading config from _sys_* tables (use config APIs or POST /api/v1/config/package to insert)");
46 let cfg = load_from_pool(&pool, DEFAULT_PACKAGE_ID)
47 .await
48 .map_err(|e| -> Box<dyn std::error::Error> { Box::new(e) })?;
49 (cfg, DEFAULT_PACKAGE_ID.to_string())
50 }
51 };
52 apply_migrations(
53 &pool,
54 &config,
55 None,
56 None,
57 dialect.as_ref(),
58 &HashMap::new(),
59 )
60 .await?;
61 let model = resolve(&config)?.with_package_id(&package_id);
62 let mut package_models = HashMap::new();
63 package_models.insert(package_id.clone(), model.clone());
64 let storage = architect_sdk::init_storage_provider().await;
65 let event_client = architect_sdk::events::DecisionHubClient::from_env();
66 let authrs_client = architect_sdk::authrs::AuthrsClient::from_env();
67 let state = AppState {
68 pool: pool.clone(),
69 model: Arc::new(RwLock::new(model)),
70 package_models: Arc::new(RwLock::new(package_models)),
71 tenant_pools: Arc::new(RwLock::new(HashMap::new())),
72 tenant_registry: Arc::new(tenant_registry),
73 storage,
74 event_client,
75 authrs_client,
76 dialect,
77 extensible_cache: Default::default(),
78 };
79
80 let api = Router::new()
81 .merge(common_routes_with_ready(state.clone()))
82 .nest("/api/v1", config_routes(state.clone()))
83 .nest("/api/v1", entity_routes(state));
84
85 let app = Router::new().nest("/", api);
86
87 let listener = TcpListener::bind("0.0.0.0:3000").await?;
88 tracing::info!("listening on {}", listener.local_addr()?);
89 axum::serve(listener, app).await?;
90 Ok(())
91}Trait Implementations§
Source§impl Clone for ResolvedModel
impl Clone for ResolvedModel
Source§fn clone(&self) -> ResolvedModel
fn clone(&self) -> ResolvedModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ResolvedModel
impl RefUnwindSafe for ResolvedModel
impl Send for ResolvedModel
impl Sync for ResolvedModel
impl Unpin for ResolvedModel
impl UnsafeUnpin for ResolvedModel
impl UnwindSafe for ResolvedModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more