diff --git a/client-sdks/reference/tauri.mdx b/client-sdks/reference/tauri.mdx index ab81d9535..58e8490f7 100644 --- a/client-sdks/reference/tauri.mdx +++ b/client-sdks/reference/tauri.mdx @@ -332,7 +332,6 @@ Connection locks and table updates are automatically shared between Rust and Jav ## Limitations -- The Rust SDK, which is used to implement the Tauri plugin, does not provide `lastSyncedAt`, `hasSynced` and `priorityStatusEntries` on `SyncStatus`. Use the status on individual Sync Streams through `SyncStatus.forStream` instead. - Connecting to the PowerSync Service is only possible from Rust. Calling `connect()` from JavaScript will throw. ## Additional Usage Examples diff --git a/client-sdks/usage-examples.mdx b/client-sdks/usage-examples.mdx index fa48a2f22..633e7798a 100644 --- a/client-sdks/usage-examples.mdx +++ b/client-sdks/usage-examples.mdx @@ -219,7 +219,21 @@ import JavaScriptCallbackWatch from '/snippets/basic-watch-query-javascript-call Also see [`ReadTransaction`](https://powersync-ja.github.io/powersync-dotnet/api/PowerSync.Common.Client.PowerSyncDatabase.ReadTransaction.html). - Example not yet available. + ```Rust + use powersync::{PowerSyncDatabase, error::PowerSyncError}; + use rusqlite::params; + + async fn delete_list(db: &PowerSyncDatabase, id: &str) -> Result<(), PowerSyncError> { + let mut writer = db.writer().await?; + let tx = writer.transaction()?; + + tx.execute("DELETE FROM lists WHERE id = ?", params![id])?; + tx.execute("DELETE FROM todos WHERE list_id = ?", params![id])?; + + tx.commit()?; + Ok(()) + } + ``` @@ -949,7 +963,22 @@ import JavaScriptCallbackWatch from '/snippets/basic-watch-query-javascript-call ``` - Example not yet available. + ```Rust + use futures_lite::StreamExt; + use powersync::PowerSyncDatabase; + + async fn observe_status(db: &PowerSyncDatabase) { + let mut stream = db.watch_status(); + // watch_status() also returns the current snapshot when first polled, but status() can be used + // if access to the status is needed synchronously. + let mut status = db.status(); + + loop { + println!("PowerSync status: {status:?}"); + status = stream.next().await.unwrap(); + } + } + ``` @@ -1128,7 +1157,17 @@ import JavaScriptCallbackWatch from '/snippets/basic-watch-query-javascript-call ``` - Example not yet available. + ```Rust + use futures_lite::StreamExt; + use powersync::PowerSyncDatabase; + + async fn wait_for_initial_sync(db: &PowerSyncDatabase) { + db.watch_status() + .filter(|status| status.has_synced()) + .next() + .await; + } + ``` @@ -1465,6 +1504,28 @@ import JavaScriptCallbackWatch from '/snippets/basic-watch-query-javascript-call - [Demo component](https://github.com/powersync-ja/powersync-dotnet/blob/main/demos/MAUITodo/Views/ListsPage.xaml.cs) - Example not yet available. + The Rust SDK doesn't report global sync progress, but can report progress for a Sync Stream. For an auto-subscribe Sync Stream named `lists`, you can track progress with: + + ```Rust + use futures_lite::StreamExt; + use powersync::PowerSyncDatabase; + + async fn print_progress(db: &PowerSyncDatabase) { + let stream = db.sync_stream("lists", None); + let mut status = db.watch_status(); + while let Some(status) = status.next().await { + let progress = status + .for_stream(&stream) + .and_then(|stream| stream.progress); + + if let Some(progress) = progress { + println!( + "Stream progress: {} out of {}", + progress.downloaded, progress.total + ); + } + } + } + ```