File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff 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).
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments