mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-17 15:14:20 +01:00
cursor: add MVCCScanCursorPosition
This commit is contained in:
@@ -39,6 +39,8 @@ MVCCError MVCCScanCursorRead(MVCCScanCursorRef cursor, uint8_t **value_ptr, int6
|
||||
|
||||
int MVCCScanCursorNext(MVCCScanCursorRef cursor);
|
||||
|
||||
uint64_t MVCCScanCursorPosition(MVCCScanCursorRef cursor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -200,7 +200,7 @@ pub unsafe extern "C" fn MVCCScanCursorRead(
|
||||
|
||||
// TODO: deduplicate with MVCCDatabaseRead()
|
||||
match runtime.block_on(async move {
|
||||
let maybe_row = cursor.current().await?;
|
||||
let maybe_row = cursor.current_row().await?;
|
||||
match maybe_row {
|
||||
Some(row) => {
|
||||
tracing::debug!("Found row {row:?}");
|
||||
@@ -243,3 +243,10 @@ pub unsafe extern "C" fn MVCCScanCursorNext(cursor: MVCCScanCursorRef) -> std::f
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn MVCCScanCursorPosition(cursor: MVCCScanCursorRef) -> u64 {
|
||||
let cursor_ctx = unsafe { &mut *cursor.ptr };
|
||||
let cursor = &mut cursor_ctx.cursor;
|
||||
cursor.current_row_id().unwrap_or(0)
|
||||
}
|
||||
@@ -36,7 +36,14 @@ impl<
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn current(&self) -> Result<Option<Row>> {
|
||||
pub fn current_row_id(&self) -> Option<u64> {
|
||||
if self.index >= self.row_ids.len() {
|
||||
return None;
|
||||
}
|
||||
Some(self.row_ids[self.index])
|
||||
}
|
||||
|
||||
pub async fn current_row(&self) -> Result<Option<Row>> {
|
||||
if self.index >= self.row_ids.len() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user