Skip to content

Commit 2966bfe

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

File tree

5 files changed

+13
-25
lines changed

5 files changed

+13
-25
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ doctest = false
99
[dependencies]
1010
anyhow = "1.0"
1111
postgres = { version = "0.19.3" }
12-
spin-engine = { path = "../engine" }
13-
spin-manifest = { path = "../manifest" }
12+
spin-core = { path = "../core" }
1413
tracing = { version = "0.1", features = [ "log" ] }
1514

1615
[dependencies.wit-bindgen-wasmtime]
1716
git = "https://github.com/bytecodealliance/wit-bindgen"
1817
rev = "cb871cfa1ee460b51eb1d144b175b9aab9c50aba"
19-
features = ["async"]
20-
18+
features = ["async"]

crates/outbound-pg/src/lib.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
use anyhow::anyhow;
2-
use outbound_pg::*;
32
use postgres::{types::ToSql, types::Type, Client, NoTls, Row};
4-
5-
pub use outbound_pg::add_to_linker;
6-
use spin_engine::{
7-
host_component::{HostComponent, HostComponentsStateHandle},
8-
RuntimeContext,
9-
};
10-
use wit_bindgen_wasmtime::{async_trait, wasmtime::Linker};
3+
use spin_core::HostComponent;
4+
use wit_bindgen_wasmtime::async_trait;
115

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

149
/// A simple implementation to support outbound pg connection
1510
#[derive(Default, Clone)]
1611
pub struct OutboundPg;
1712

1813
impl HostComponent for OutboundPg {
19-
type State = Self;
14+
type Data = Self;
2015

2116
fn add_to_linker<T: Send>(
22-
linker: &mut Linker<RuntimeContext<T>>,
23-
state_handle: HostComponentsStateHandle<Self::State>,
17+
linker: &mut spin_core::Linker<T>,
18+
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
2419
) -> anyhow::Result<()> {
25-
add_to_linker(linker, move |ctx| state_handle.get_mut(ctx))
20+
outbound_pg::add_to_linker(linker, get)
2621
}
2722

28-
fn build_state(
29-
&self,
30-
_component: &spin_manifest::CoreComponent,
31-
) -> anyhow::Result<Self::State> {
32-
Ok(Self)
23+
fn build_data(&self) -> Self::Data {
24+
Default::default()
3325
}
3426
}
3527

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)?;
9999
self.loader.add_dynamic_host_component(
100100
&mut builder,
101101
outbound_http::OutboundHttpComponent,

crates/trigger/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +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)?;
133132
Ok(())
134133
}

0 commit comments

Comments
 (0)