pub struct Cursor { /* private fields */ }Expand description
A database cursor for iterating over records.
Cursors are used for operating on collections of records, for iterating over a database, and for saving handles to individual records so they can be modified after reading.
§Example
use noxu_db::{Database, DatabaseEntry, Get};
let mut cursor = db.open_cursor(None, None)?;
let mut key = DatabaseEntry::new();
let mut data = DatabaseEntry::new();
// Iterate through all records
while cursor.get(&mut key, &mut data, Get::Next, None)? == OperationStatus::Success {
// Process key and data
}
cursor.close()?;Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn get(
&mut self,
key: &mut DatabaseEntry,
data: &mut DatabaseEntry,
get_type: Get,
_lock_mode: Option<LockMode>,
) -> Result<OperationStatus>
pub fn get( &mut self, key: &mut DatabaseEntry, data: &mut DatabaseEntry, get_type: Get, _lock_mode: Option<LockMode>, ) -> Result<OperationStatus>
Retrieve a record using the cursor.
§Arguments
key— search input (forGet::Search/Get::SearchGte) or the output buffer that receives the discovered key (for iteration / range search variants).data— output buffer for the record’s value.get_type— selects the navigation primitive (seeGet).lock_mode— reserved for per-operation isolation overrides (e.g., dirty reads inside an otherwise-serializable txn). The current implementation ignores this argument and uses the surrounding transaction’s isolation level (set oncrate::transaction_config::TransactionConfig). Per-call read-uncommitted is not yet implemented; passNonefor now.
§Returns
OperationStatus::Successif the cursor positioned on a record.OperationStatus::NotFoundif no record satisfied the request.
§Errors
NoxuError::DatabaseClosedif the underlying database has been closed.NoxuError::OperationNotAllowedif the cursor was passed aGet::Currentrequest before being positioned by an earlier call, or if an underlying B-tree operation rejected the request.
Sourcepub fn put(
&mut self,
key: &DatabaseEntry,
data: &DatabaseEntry,
put_type: Put,
) -> Result<OperationStatus>
pub fn put( &mut self, key: &DatabaseEntry, data: &DatabaseEntry, put_type: Put, ) -> Result<OperationStatus>
Store a record using the cursor.
§Arguments
key- Key to storedata- Data to storeput_type- Type of put operation
Store a record using the cursor.
§Arguments
key— the record’s key. Empty keys (get_data()returnsNoneor an empty slice) are forwarded to the underlying B-tree which rejects them on writable databases.data— the record’s value.put_type— seePutfor the per-mode semantics.
§Returns
OperationStatus::Successif the record was inserted or updated.OperationStatus::KeyExistsforPut::NoOverwrite/Put::NoDupDatawhen the key (or(key, data)pair under sorted-dup) already exists.
§Errors
NoxuError::DatabaseClosedif the underlying database has been closed.NoxuError::OperationNotAllowedif the cursor was opened read-only, or if the call usesPut::Currentbefore the cursor was positioned.
Sourcepub fn delete(&mut self) -> Result<OperationStatus>
pub fn delete(&mut self) -> Result<OperationStatus>
Delete the record at the current cursor position.
§Returns
OperationStatus::Success if the record was deleted,
OperationStatus::NotFound if the cursor is not positioned.
Sourcepub fn count(&self) -> Result<u64>
pub fn count(&self) -> Result<u64>
Count the number of records with the same key.
For non-duplicate databases this returns 1 when positioned and
0 otherwise. For sorted-dup databases it returns the number
of duplicate values stored under the cursor’s current key.
§Returns
The count of records, or 0 if the cursor is not currently
positioned on a record.
§Errors
NoxuError::DatabaseClosedif the underlying database has been closed.NoxuError::OperationNotAllowedif the underlying B-tree count operation fails (e.g., the cursor was invalidated by a concurrent close).
Sourcepub fn close(&mut self) -> Result<()>
pub fn close(&mut self) -> Result<()>
Close the cursor.
The cursor handle may not be used again after this call. Any
subsequent navigation / mutation operation returns
NoxuError::OperationNotAllowed.
close() itself is idempotent: calling it more than once is a
no-op and returns Ok(()). This matches BDB-JE’s
Cursor.close() contract — calling it more than once is safe.
§Errors
Returns the inner-cursor close error if the underlying
CursorImpl::close fails — currently the inner close is
infallible after the first call, so this only surfaces internal
invariant violations.
Sourcepub fn get_state(&self) -> CursorState
pub fn get_state(&self) -> CursorState
Get the current cursor state.
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if the cursor is read-only.