diff options
Diffstat (limited to 'filamento')
-rw-r--r-- | filamento/examples/example.rs | 8 | ||||
-rw-r--r-- | filamento/src/db.rs | 22 |
2 files changed, 17 insertions, 13 deletions
diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs index 12ede0d..8ebfde0 100644 --- a/filamento/examples/example.rs +++ b/filamento/examples/example.rs @@ -52,10 +52,10 @@ async fn main() { client.connect().await.unwrap(); tokio::time::sleep(Duration::from_secs(5)).await; info!("changing nick"); - // client - // .change_nick(Some("britney".to_string())) - // .await - // .unwrap(); + client + .change_nick(Some("britney".to_string())) + .await + .unwrap(); info!("sending message"); client .send_message( diff --git a/filamento/src/db.rs b/filamento/src/db.rs index cdc7520..51d99e6 100644 --- a/filamento/src/db.rs +++ b/filamento/src/db.rs @@ -78,10 +78,11 @@ impl Db { /// returns whether or not the nickname was updated pub(crate) async fn delete_user_nick(&self, jid: JID) -> Result<bool, Error> { if sqlx::query!( - "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ?", + "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ? where nick is not ?", jid, None::<String>, None::<String>, + None::<String>, ) .execute(&self.db) .await? @@ -96,17 +97,18 @@ impl Db { /// returns whether or not the nickname was updated pub(crate) async fn upsert_user_nick(&self, jid: JID, nick: String) -> Result<bool, Error> { - if sqlx::query!( - "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ?", + let rows_affected = sqlx::query!( + "insert into users (jid, nick) values (?, ?) on conflict do update set nick = ? where nick is not ?", jid, nick, + nick, nick ) .execute(&self.db) .await? - .rows_affected() - > 0 - { + .rows_affected(); + tracing::debug!("rows affected: {}", rows_affected); + if rows_affected > 0 { Ok(true) } else { Ok(false) @@ -129,10 +131,11 @@ impl Db { .map(|row: AvatarRow| row.avatar) .unwrap_or(None); if sqlx::query!( - "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ?", + "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ? where avatar is not ?", jid, None::<String>, None::<String>, + None::<String>, ) .execute(&self.db) .await? @@ -162,10 +165,11 @@ impl Db { .map(|row: AvatarRow| row.avatar) .unwrap_or(None); if sqlx::query!( - "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ?", + "insert into users (jid, avatar) values (?, ?) on conflict do update set avatar = ? where avatar is not ?", jid, avatar, - avatar + avatar, + avatar, ) .execute(&self.db) .await? |