pub struct DecisionHubClient { /* private fields */ }Implementations§
Source§impl DecisionHubClient
impl DecisionHubClient
Sourcepub fn from_env() -> Option<Arc<Self>>
pub fn from_env() -> Option<Arc<Self>>
Examples found in repository?
examples/server.rs (line 65)
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}Auto Trait Implementations§
impl !RefUnwindSafe for DecisionHubClient
impl !UnwindSafe for DecisionHubClient
impl Freeze for DecisionHubClient
impl Send for DecisionHubClient
impl Sync for DecisionHubClient
impl Unpin for DecisionHubClient
impl UnsafeUnpin for DecisionHubClient
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
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