Skip to content

Commit c82e9e0

Browse files
committed
add missed method Cursor::primary_key
1 parent 385930c commit c82e9e0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/cursor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ impl<Err> Cursor<Err> {
172172
})
173173
}
174174

175+
/// Retrieve the primary key this [`Cursor`] is currently pointing at, or `None` if the cursor is completed
176+
///
177+
/// Internally, this uses the [`IDBCursor::primaryKey`](https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/key) property.
178+
pub fn primary_key(&self) -> Option<JsValue> {
179+
self.sys.as_ref().map(|sys| {
180+
sys.primary_key()
181+
.expect("Failed retrieving primary key from known-good cursor")
182+
})
183+
}
184+
175185
/// Advance this [`Cursor`] by `count` elements
176186
///
177187
/// Internally, this uses [`IDBCursor::advance`](https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/advance).

tests/js.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,16 @@ async fn smoke_test() {
200200
let mut all = Vec::new();
201201
let mut cursor = stuffs.cursor().open().await.unwrap();
202202
while let Some(val) = cursor.value() {
203-
all.push(val);
203+
all.push((cursor.primary_key().unwrap(), val));
204204
cursor.delete().await.unwrap();
205205
cursor.advance(1).await.unwrap();
206206
}
207207
assert_eq!(
208208
all,
209209
vec![
210-
(**JsString::from("value3")).clone(),
211-
(**JsString::from("value2")).clone(),
212-
(**JsString::from("value1")).clone()
210+
(JsValue::from(3), (**JsString::from("value3")).clone()),
211+
(JsValue::from(4), (**JsString::from("value2")).clone()),
212+
(JsValue::from(5), (**JsString::from("value1")).clone())
213213
]
214214
);
215215
assert_eq!(stuffs.count().await.unwrap(), 0);

0 commit comments

Comments
 (0)