cursor: add is_empty

This commit is contained in:
Piotr Sarna
2023-05-12 10:09:18 +02:00
parent d5eec5d528
commit a782ae5a0a
2 changed files with 11 additions and 1 deletions

View File

@@ -156,6 +156,12 @@ pub unsafe extern "C" fn MVCCScanCursorOpen(db: MVCCDatabaseRef) -> MVCCScanCurs
let (database, runtime) = (&database.db, &database.runtime);
match runtime.block_on(async move { mvcc_rs::cursor::ScanCursor::new(database).await }) {
Ok(cursor) => {
if cursor.is_empty() {
tracing::debug!("Cursor is empty");
return MVCCScanCursorRef {
ptr: std::ptr::null_mut(),
};
}
tracing::debug!("Cursor open: {cursor:?}");
MVCCScanCursorRef {
ptr: Box::into_raw(Box::new(ScanCursorContext { cursor, db })),
@@ -249,4 +255,4 @@ pub unsafe extern "C" fn MVCCScanCursorPosition(cursor: MVCCScanCursorRef) -> u6
let cursor_ctx = unsafe { &mut *cursor.ptr };
let cursor = &mut cursor_ctx.cursor;
cursor.current_row_id().unwrap_or(0)
}
}

View File

@@ -59,4 +59,8 @@ impl<
self.index += 1;
self.index < self.row_ids.len()
}
pub fn is_empty(&self) -> bool {
self.index >= self.row_ids.len()
}
}