Skip to main content

wasm_sql/
lib.rs

1pub mod core;
2pub mod sqldb;
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
8pub mod sqlite;
9
10use anyhow::Ok;
11use wasmtime::component::Linker;
12
13pub use crate::core::bindings::SqlHostState;
14
15pub trait SqlHostStateView: Send {
16    fn sql_host_state(&mut self) -> &mut SqlHostState;
17}
18
19macro_rules! getter {
20    ($T:ty) => {
21        |state: &mut $T| state.sql_host_state()
22    };
23}
24
25pub fn add_to_linker<T: SqlHostStateView>(linker: &mut Linker<T>) -> anyhow::Result<()> {
26    core::bindings::generated::Host_::add_to_linker::<T, SqlHostState>(linker, getter!(T))?;
27
28    #[cfg(feature = "postgres")]
29    {
30        postgres::bindings::generated::wasm_sql::postgres::codecs::add_to_linker::<T, SqlHostState>(
31            linker,
32            getter!(T),
33        )?;
34    }
35
36    #[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
37    {
38        sqlite::bindings::generated::wasm_sql::sqlite::codecs::add_to_linker::<T, SqlHostState>(
39            linker,
40            getter!(T),
41        )?;
42    }
43
44    Ok(())
45}