udb/backend/plugins/
postgres.rs1use crate::backend::BackendKind;
9use crate::backend::plugin::{Backend, RegisterCtx};
10
11#[derive(Debug, Default)]
13pub struct PostgresPlugin;
14
15pub static PLUGIN: PostgresPlugin = PostgresPlugin;
17
18#[async_trait::async_trait]
19impl Backend for PostgresPlugin {
20 fn kind(&self) -> BackendKind {
21 BackendKind::Postgres
22 }
23
24 async fn register(&self, ctx: &mut RegisterCtx<'_>) {
25 crate::runtime::core::setup_data::register_postgres(ctx).await;
26 }
27}
28
29impl crate::runtime::executors::handle::DispatchFactory for PostgresPlugin {
30 fn build_dispatch_executor(
31 &self,
32 runtime: &crate::runtime::core::DataBrokerRuntime,
33 instance: Option<&str>,
34 _write: bool,
35 context: Option<&crate::broker::RequestContext>,
36 ) -> Result<crate::runtime::executors::handle::DispatchExecutor, tonic::Status> {
37 let pool = runtime.pg_pool_for_instance(instance)?.clone();
45 let executor = match context {
46 Some(ctx) => crate::runtime::executors::postgres::PostgresExecutor::with_context(
47 pool,
48 std::sync::Arc::new(ctx.clone()),
49 ),
50 None => crate::runtime::executors::postgres::PostgresExecutor::with_pool(pool),
51 };
52 Ok(crate::runtime::executors::handle::DispatchExecutor::Postgres(executor))
53 }
54}