Skip to main content

wasm_sql/
lib.rs

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