Skip to content

Commit 5705e5e

Browse files
committed
update readme with example
1 parent 8fdc2a1 commit 5705e5e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ async fn example() -> anyhow::Result<()> {
9595
})
9696
.await?;
9797

98+
// More complex example: using cursors to iterate over a store
99+
db.transaction(&["store"])
100+
.run(|t| async move {
101+
let mut all_items = Vec::new();
102+
let mut cursor = t.object_store("store")?.cursor().open().await?;
103+
while let Some(value) = cursor.value() {
104+
all_items.push(value);
105+
cursor.advance(1).await?;
106+
}
107+
assert_eq!(all_items.len(), 3);
108+
assert_eq!(all_items[0], **JsString::from("foo"));
109+
Ok(())
110+
})
111+
.await?;
112+
98113
Ok(())
99114
}
100115
```

examples/basic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ async fn example() -> anyhow::Result<()> {
7474
})
7575
.await?;
7676

77+
// More complex example: using cursors to iterate over a store
78+
db.transaction(&["store"])
79+
.run(|t| async move {
80+
let mut all_items = Vec::new();
81+
let mut cursor = t.object_store("store")?.cursor().open().await?;
82+
while let Some(value) = cursor.value() {
83+
all_items.push(value);
84+
cursor.advance(1).await?;
85+
}
86+
assert_eq!(all_items.len(), 3);
87+
assert_eq!(all_items[0], **JsString::from("foo"));
88+
Ok(())
89+
})
90+
.await?;
91+
7792
Ok(())
7893
}
7994

0 commit comments

Comments
 (0)