Skip to content

Commit 81a3629

Browse files
committed
Migrate outbound-pg to new core
Signed-off-by: Lann Martin <lann.martin@fermyon.com>
1 parent ad71a33 commit 81a3629

File tree

5 files changed

+14
-28
lines changed

5 files changed

+14
-28
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/outbound-pg/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ doctest = false
88

99
[dependencies]
1010
anyhow = "1.0"
11-
tokio-postgres = { version = "0.7.7" }
12-
spin-engine = { path = "../engine" }
13-
spin-manifest = { path = "../manifest" }
11+
spin-core = { path = "../core" }
1412
tokio = { version = "1", features = [ "rt-multi-thread" ] }
13+
tokio-postgres = { version = "0.7.7" }
1514
tracing = { version = "0.1", features = [ "log" ] }
1615

1716
[dependencies.wit-bindgen-wasmtime]

crates/outbound-pg/src/lib.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
use anyhow::anyhow;
2-
use outbound_pg::*;
2+
use spin_core::HostComponent;
33
use std::collections::HashMap;
44
use tokio_postgres::{
55
types::{ToSql, Type},
66
Client, NoTls, Row,
77
};
8-
9-
pub use outbound_pg::add_to_linker;
10-
use spin_engine::{
11-
host_component::{HostComponent, HostComponentsStateHandle},
12-
RuntimeContext,
13-
};
14-
use wit_bindgen_wasmtime::{async_trait, wasmtime::Linker};
8+
use wit_bindgen_wasmtime::async_trait;
159

1610
wit_bindgen_wasmtime::export!({paths: ["../../wit/ephemeral/outbound-pg.wit"], async: *});
11+
use outbound_pg::{Column, DbDataType, DbValue, ParameterValue, PgError, RowSet};
1712

1813
/// A simple implementation to support outbound pg connection
14+
#[derive(Default)]
1915
pub struct OutboundPg {
2016
pub connections: HashMap<String, Client>,
2117
}
2218

2319
impl HostComponent for OutboundPg {
24-
type State = Self;
20+
type Data = Self;
2521

2622
fn add_to_linker<T: Send>(
27-
linker: &mut Linker<RuntimeContext<T>>,
28-
state_handle: HostComponentsStateHandle<Self::State>,
23+
linker: &mut spin_core::Linker<T>,
24+
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
2925
) -> anyhow::Result<()> {
30-
add_to_linker(linker, move |ctx| state_handle.get_mut(ctx))
26+
outbound_pg::add_to_linker(linker, get)
3127
}
3228

33-
fn build_state(
34-
&self,
35-
_component: &spin_manifest::CoreComponent,
36-
) -> anyhow::Result<Self::State> {
37-
let connections = std::collections::HashMap::new();
38-
39-
Ok(Self { connections })
29+
fn build_data(&self) -> Self::Data {
30+
Default::default()
4031
}
4132
}
4233

crates/trigger-new/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<Executor: TriggerExecutor> TriggerExecutorBuilder<Executor> {
9595
if !self.disable_default_host_components {
9696
// FIXME(lann): migrate host components from prototype
9797
// builder.add_host_component(outbound_redis::OutboundRedis::default())?;
98-
// builder.add_host_component(outbound_pg::OutboundPg)?;
98+
builder.add_host_component(outbound_pg::OutboundPg::default())?;
9999
self.loader.add_dynamic_host_component(
100100
&mut builder,
101101
outbound_http::OutboundHttpComponent,

crates/trigger/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,5 @@ pub fn add_default_host_components<T: Default + Send + 'static>(
129129
builder.add_host_component(outbound_redis::OutboundRedis {
130130
connections: Arc::new(RwLock::new(HashMap::new())),
131131
})?;
132-
builder.add_host_component(outbound_pg::OutboundPg {
133-
connections: HashMap::new(),
134-
})?;
135132
Ok(())
136133
}

0 commit comments

Comments
 (0)