wasm-sql 0.1.6

Wasmtime host implementation for a SQL component WIT interface. Enables Wasm components to interact with SQL databases via the WebAssembly Component Model.
Documentation
pub mod core;
pub mod sqldb;

pub use wasmtime;

#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
pub mod sqlite;

use anyhow::Ok;
use wasmtime::component::Linker;

pub use crate::core::bindings::SqlHostState;

pub trait SqlHostStateView: Send {
    fn sql_host_state(&mut self) -> &mut SqlHostState;
}

macro_rules! getter {
    ($T:ty) => {
        |state: &mut $T| state.sql_host_state()
    };
}

pub fn add_to_linker<T: SqlHostStateView>(linker: &mut Linker<T>) -> anyhow::Result<()> {
    core::bindings::generated::Host_::add_to_linker::<T, SqlHostState>(linker, getter!(T))?;

    #[cfg(feature = "postgres")]
    {
        postgres::bindings::generated::wasm_sql::postgres::codecs::add_to_linker::<T, SqlHostState>(
            linker,
            getter!(T),
        )?;
    }

    #[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
    {
        sqlite::bindings::generated::wasm_sql::sqlite::codecs::add_to_linker::<T, SqlHostState>(
            linker,
            getter!(T),
        )?;
    }

    Ok(())
}