From 61b755c890dcaa66daa35942ca87cc00269b0fe9 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 17 Apr 2025 17:30:22 +0100 Subject: feat(filamento): full wasm support by switching to rusqlite --- jid/Cargo.toml | 2 ++ jid/src/lib.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'jid') diff --git a/jid/Cargo.toml b/jid/Cargo.toml index e3cf7c7..439ef75 100644 --- a/jid/Cargo.toml +++ b/jid/Cargo.toml @@ -5,9 +5,11 @@ edition = "2021" [features] # default = [] +rusqlite = ["dep:rusqlite"] # sqlx = ["dep:sqlx"] [dependencies] +rusqlite = { git = "https://github.com/Spxg/rusqlite.git", optional = true, branch = "wasm-demo" } # sqlx = { version = "0.8.3", features = ["sqlite"], optional = true } # sqlx = { path = "../../remote/sqlx", features = ["sqlite"], optional = true } diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 8f297c6..9301f59 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -33,6 +33,29 @@ impl Display for JID { } } +#[cfg(feature = "rusqlite")] +impl rusqlite::ToSql for JID { + fn to_sql(&self) -> rusqlite::Result> { + Ok(rusqlite::types::ToSqlOutput::Owned( + rusqlite::types::Value::Text(self.to_string()), + )) + } +} + +#[cfg(feature = "rusqlite")] +impl rusqlite::types::FromSql for JID { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + Ok(JID::from_str(value.as_str()?)?) + } +} + +#[cfg(feature = "rusqlite")] +impl From for rusqlite::types::FromSqlError { + fn from(value: ParseError) -> Self { + Self::Other(Box::new(value)) + } +} + #[cfg(feature = "sqlx")] impl sqlx::Type for JID { fn type_info() -> ::TypeInfo { -- cgit