diff options
| author | 2025-04-17 11:24:43 +0100 | |
|---|---|---|
| committer | 2025-04-17 11:24:43 +0100 | |
| commit | 26d0ee51e232b793bc83ba565c0e9ab820d8d0db (patch) | |
| tree | 26596552b1c7692fe9b4c95a9b254299273f2432 /filamento | |
| parent | b9d75f38743113c054be3d97af36bdd2a7dd0d69 (diff) | |
| download | luz-26d0ee51e232b793bc83ba565c0e9ab820d8d0db.tar.gz luz-26d0ee51e232b793bc83ba565c0e9ab820d8d0db.tar.bz2 luz-26d0ee51e232b793bc83ba565c0e9ab820d8d0db.zip | |
feat(filamento): remove sqlx
Diffstat (limited to '')
| -rw-r--r-- | filamento/Cargo.toml | 8 | ||||
| -rw-r--r-- | filamento/src/chat.rs | 51 | ||||
| -rw-r--r-- | filamento/src/db.rs | 13 | ||||
| -rw-r--r-- | filamento/src/error.rs | 26 | ||||
| -rw-r--r-- | filamento/src/presence.rs | 41 | ||||
| -rw-r--r-- | filamento/src/roster.rs | 50 | ||||
| -rw-r--r-- | filamento/src/user.rs | 2 | 
7 files changed, 27 insertions, 164 deletions
| diff --git a/filamento/Cargo.toml b/filamento/Cargo.toml index 4c36c95..66cbc31 100644 --- a/filamento/Cargo.toml +++ b/filamento/Cargo.toml @@ -7,12 +7,12 @@ edition = "2024"  futures = "0.3.31"  lampada = { version = "0.1.0", path = "../lampada" }  tokio = { workspace = true } -# tokio = "1.42.0"  thiserror = "2.0.11"  stanza = { version = "0.1.0", path = "../stanza", features = ["rfc_6121", "xep_0203", "xep_0030", "xep_0060", "xep_0172", "xep_0390", "xep_0128", "xep_0115", "xep_0084"] }  # TODO: re-export jid? -jid = { version = "0.1.0", path = "../jid", features = ["sqlx"] } +jid = { version = "0.1.0", path = "../jid" }  uuid = { version = "1.13.1", features = ["v4"] } +rusqlite = { git = "https://github.com/Spxg/rusqlite.git" }  tracing = "0.1.41"  chrono = "0.4.40"  sha2 = "0.10.8" @@ -24,14 +24,10 @@ hex = "0.4.3"  [target.'cfg(not(target_arch = "wasm32"))'.dependencies]  tokio = { workspace = true, features = ["sync", "time", "rt", "fs"] } -sqlx = { path = "../../remote/sqlx", features = ["sqlite", "runtime-tokio", "uuid", "chrono"] }  [target.'cfg(target_arch = "wasm32")'.dependencies]  tokio = { workspace = true, features = ["sync", "time", "rt"] } -# tokio = { version = "1.44.3", features = [] } -sqlx = { path = "../../remote/sqlx", features = ["sqlite-precompiled-wasm", "runtime-tokio", "uuid", "chrono"] }  tokio_with_wasm = { version = "0.8.2", features = ["sync", "time", "rt"] } -# wasm-bindgen-futures = "0.4"  [dev-dependencies]  tracing-subscriber = "0.3.19" diff --git a/filamento/src/chat.rs b/filamento/src/chat.rs index 147c7f7..557b42b 100644 --- a/filamento/src/chat.rs +++ b/filamento/src/chat.rs @@ -1,13 +1,11 @@  use chrono::{DateTime, Utc};  use jid::JID; -use sqlx::Sqlite;  use uuid::Uuid; -#[derive(Debug, sqlx::FromRow, Clone)] +#[derive(Debug, Clone)]  pub struct Message {      pub id: Uuid,      // does not contain full user information -    #[sqlx(rename = "from_jid")]      // bare jid (for now)      pub from: JID,      pub delivery: Option<Delivery>, @@ -15,7 +13,6 @@ pub struct Message {      // TODO: originally_from      // TODO: message edits      // TODO: message timestamp -    #[sqlx(flatten)]      pub body: Body,  } @@ -30,61 +27,19 @@ pub enum Delivery {      Queued,  } -impl sqlx::Type<Sqlite> for Delivery { -    fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo { -        <&str as sqlx::Type<Sqlite>>::type_info() -    } -} - -impl sqlx::Decode<'_, Sqlite> for Delivery { -    fn decode( -        value: <Sqlite as sqlx::Database>::ValueRef<'_>, -    ) -> Result<Self, sqlx::error::BoxDynError> { -        let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?; -        match value { -            "sending" => Ok(Self::Sending), -            "written" => Ok(Self::Written), -            "sent" => Ok(Self::Sent), -            "delivered" => Ok(Self::Delivered), -            "read" => Ok(Self::Read), -            "failed" => Ok(Self::Failed), -            "queued" => Ok(Self::Queued), -            _ => unreachable!(), -        } -    } -} - -impl sqlx::Encode<'_, Sqlite> for Delivery { -    fn encode_by_ref( -        &self, -        buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>, -    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> { -        let value = match self { -            Delivery::Sending => "sending", -            Delivery::Written => "written", -            Delivery::Sent => "sent", -            Delivery::Delivered => "delivered", -            Delivery::Read => "read", -            Delivery::Failed => "failed", -            Delivery::Queued => "queued", -        }; -        <&str as sqlx::Encode<Sqlite>>::encode(value, buf) -    } -} -  // TODO: user migrations  // pub enum Migrated {  //     Jabber(User),  //     Outside,  // } -#[derive(Debug, sqlx::FromRow, Clone)] +#[derive(Debug, Clone)]  pub struct Body {      // TODO: rich text, other contents, threads      pub body: String,  } -#[derive(sqlx::FromRow, Debug, Clone)] +#[derive(Debug, Clone)]  pub struct Chat {      pub correspondent: JID,      pub have_chatted: bool, diff --git a/filamento/src/db.rs b/filamento/src/db.rs index e3bfdac..467030d 100644 --- a/filamento/src/db.rs +++ b/filamento/src/db.rs @@ -2,7 +2,6 @@ use std::{collections::HashSet, path::Path};  use chrono::{DateTime, Utc};  use jid::JID; -use sqlx::{SqlitePool, migrate};  use uuid::Uuid;  use crate::{ @@ -41,8 +40,8 @@ impl Db {                  .to_str()                  .ok_or(DatabaseOpenError::InvalidPath)?          ); -        let db = SqlitePool::connect(&url).await?; -        migrate!().run(&db).await?; +        // let db = SqlitePool::connect(&url).await?; +        // migrate!().run(&db).await?;          // Ok(Self { db })          Ok(Self {})      } @@ -57,10 +56,10 @@ impl Db {          Ok(Self {})      } -    pub(crate) fn new(db: SqlitePool) -> Self { -        // Self { db } -        Self {} -    } +    // pub(crate) fn new(db: SqlitePool) -> Self { +    //     // Self { db } +    //     Self {} +    // }      pub(crate) async fn create_user(&self, user: User) -> Result<(), Error> {          Ok(()) diff --git a/filamento/src/error.rs b/filamento/src/error.rs index f2bf6ef..6b7d0ae 100644 --- a/filamento/src/error.rs +++ b/filamento/src/error.rs @@ -166,16 +166,16 @@ pub enum ResponseError {  #[derive(Debug, Error, Clone)]  #[error("database error: {0}")] -pub struct DatabaseError(pub Arc<sqlx::Error>); +pub struct DatabaseError(pub Arc<rusqlite::Error>); -impl From<sqlx::Error> for DatabaseError { -    fn from(e: sqlx::Error) -> Self { +impl From<rusqlite::Error> for DatabaseError { +    fn from(e: rusqlite::Error) -> Self {          Self(Arc::new(e))      }  } -impl From<sqlx::Error> for DatabaseOpenError { -    fn from(e: sqlx::Error) -> Self { +impl From<rusqlite::Error> for DatabaseOpenError { +    fn from(e: rusqlite::Error) -> Self {          Self::Error(Arc::new(e))      }  } @@ -202,20 +202,20 @@ pub enum IqProcessError {  #[derive(Debug, Error, Clone)]  pub enum DatabaseOpenError {      #[error("error: {0}")] -    Error(Arc<sqlx::Error>), -    #[error("migration: {0}")] -    Migration(Arc<sqlx::migrate::MigrateError>), +    Error(Arc<rusqlite::Error>), +    // #[error("migration: {0}")] +    // Migration(Arc<rusqlite::migrate::MigrateError>),      #[error("io: {0}")]      Io(Arc<tokio::io::Error>),      #[error("invalid path")]      InvalidPath,  } -impl From<sqlx::migrate::MigrateError> for DatabaseOpenError { -    fn from(e: sqlx::migrate::MigrateError) -> Self { -        Self::Migration(Arc::new(e)) -    } -} +// impl From<sqlx::migrate::MigrateError> for DatabaseOpenError { +//     fn from(e: sqlx::migrate::MigrateError) -> Self { +//         Self::Migration(Arc::new(e)) +//     } +// }  impl From<tokio::io::Error> for DatabaseOpenError {      fn from(e: tokio::io::Error) -> Self { diff --git a/filamento/src/presence.rs b/filamento/src/presence.rs index a7a8965..e406cce 100644 --- a/filamento/src/presence.rs +++ b/filamento/src/presence.rs @@ -1,15 +1,12 @@  use chrono::{DateTime, Utc}; -use sqlx::Sqlite;  use stanza::{client::presence::String1024, xep_0203::Delay};  use crate::caps; -#[derive(Debug, Default, sqlx::FromRow, Clone)] +#[derive(Debug, Default, Clone)]  pub struct Online {      pub show: Option<Show>, -    #[sqlx(rename = "message")]      pub status: Option<String>, -    #[sqlx(skip)]      pub priority: Option<i8>,  } @@ -21,42 +18,6 @@ pub enum Show {      ExtendedAway,  } -impl sqlx::Type<Sqlite> for Show { -    fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo { -        <&str as sqlx::Type<Sqlite>>::type_info() -    } -} - -impl sqlx::Decode<'_, Sqlite> for Show { -    fn decode( -        value: <Sqlite as sqlx::Database>::ValueRef<'_>, -    ) -> Result<Self, sqlx::error::BoxDynError> { -        let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?; -        match value { -            "away" => Ok(Self::Away), -            "chat" => Ok(Self::Chat), -            "do-not-disturb" => Ok(Self::DoNotDisturb), -            "extended-away" => Ok(Self::ExtendedAway), -            _ => unreachable!(), -        } -    } -} - -impl sqlx::Encode<'_, Sqlite> for Show { -    fn encode_by_ref( -        &self, -        buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>, -    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> { -        let value = match self { -            Show::Away => "away", -            Show::Chat => "chat", -            Show::DoNotDisturb => "do-not-disturb", -            Show::ExtendedAway => "extended-away", -        }; -        <&str as sqlx::Encode<Sqlite>>::encode(value, buf) -    } -} -  #[derive(Debug, Default, Clone)]  pub struct Offline {      pub status: Option<String>, diff --git a/filamento/src/roster.rs b/filamento/src/roster.rs index 43c32f5..ba5b3cd 100644 --- a/filamento/src/roster.rs +++ b/filamento/src/roster.rs @@ -1,14 +1,13 @@  use std::collections::HashSet;  use jid::JID; -use sqlx::Sqlite;  pub struct ContactUpdate {      pub name: Option<String>,      pub groups: HashSet<String>,  } -#[derive(Debug, sqlx::FromRow, Clone)] +#[derive(Debug, Clone)]  pub struct Contact {      // jid is the id used to reference everything, but not the primary key      pub user_jid: JID, @@ -18,7 +17,6 @@ pub struct Contact {      // TODO: avatar, nickname      /// nickname picked by contact      // nickname: Option<String>, -    #[sqlx(skip)]      pub groups: HashSet<String>,  } @@ -37,52 +35,6 @@ pub enum Subscription {      // Remove,  } -impl sqlx::Type<Sqlite> for Subscription { -    fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo { -        <&str as sqlx::Type<Sqlite>>::type_info() -    } -} - -impl sqlx::Decode<'_, Sqlite> for Subscription { -    fn decode( -        value: <Sqlite as sqlx::Database>::ValueRef<'_>, -    ) -> Result<Self, sqlx::error::BoxDynError> { -        let value = <&str as sqlx::Decode<Sqlite>>::decode(value)?; -        match value { -            "none" => Ok(Self::None), -            "pending-out" => Ok(Self::PendingOut), -            "pending-in" => Ok(Self::PendingIn), -            "pending-in-pending-out" => Ok(Self::PendingInPendingOut), -            "only-out" => Ok(Self::OnlyOut), -            "only-in" => Ok(Self::OnlyIn), -            "out-pending-in" => Ok(Self::OutPendingIn), -            "in-pending-out" => Ok(Self::InPendingOut), -            "buddy" => Ok(Self::Buddy), -            _ => panic!("unexpected subscription `{value}`"), -        } -    } -} - -impl sqlx::Encode<'_, Sqlite> for Subscription { -    fn encode_by_ref( -        &self, -        buf: &mut <Sqlite as sqlx::Database>::ArgumentBuffer<'_>, -    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> { -        let value = match self { -            Subscription::None => "none", -            Subscription::PendingOut => "pending-out", -            Subscription::PendingIn => "pending-in", -            Subscription::PendingInPendingOut => "pending-in-pending-out", -            Subscription::OnlyOut => "only-out", -            Subscription::OnlyIn => "only-in", -            Subscription::OutPendingIn => "out-pending-in", -            Subscription::InPendingOut => "in-pending-out", -            Subscription::Buddy => "buddy", -        }; -        <&str as sqlx::Encode<Sqlite>>::encode(value, buf) -    } -} -  // none  // >  // >> diff --git a/filamento/src/user.rs b/filamento/src/user.rs index 8669fc3..b2ea8e4 100644 --- a/filamento/src/user.rs +++ b/filamento/src/user.rs @@ -1,6 +1,6 @@  use jid::JID; -#[derive(Debug, sqlx::FromRow, Clone)] +#[derive(Debug, Clone)]  pub struct User {      pub jid: JID,      pub nick: Option<String>, | 
