Skip to main content

mxr_store/
sync_cursor.rs

1use mxr_core::{AccountId, SyncCursor};
2
3impl super::Store {
4    pub async fn get_sync_cursor(
5        &self,
6        account_id: &AccountId,
7    ) -> Result<Option<SyncCursor>, sqlx::Error> {
8        let aid = account_id.as_str();
9        let row = sqlx::query!("SELECT sync_cursor FROM accounts WHERE id = ?", aid,)
10            .fetch_optional(self.reader())
11            .await?;
12
13        match row {
14            Some(r) => Ok(r.sync_cursor.and_then(|c| serde_json::from_str(&c).ok())),
15            None => Ok(None),
16        }
17    }
18
19    pub async fn set_sync_cursor(
20        &self,
21        account_id: &AccountId,
22        cursor: &SyncCursor,
23    ) -> Result<(), sqlx::Error> {
24        let cursor_json = serde_json::to_string(cursor).unwrap();
25        let aid = account_id.as_str();
26        sqlx::query!(
27            "UPDATE accounts SET sync_cursor = ? WHERE id = ?",
28            cursor_json,
29            aid,
30        )
31        .execute(self.writer())
32        .await?;
33        Ok(())
34    }
35}