pub struct PrimaryScan<PrimaryTable, T: Input>{ /* private fields */ }
Expand description
Scan values from the database.
Implementations§
Source§impl<PrimaryTable, T: Input> PrimaryScan<PrimaryTable, T>
impl<PrimaryTable, T: Input> PrimaryScan<PrimaryTable, T>
Sourcepub fn all(&self) -> PrimaryScanIterator<'_, T> ⓘ
pub fn all(&self) -> PrimaryScanIterator<'_, T> ⓘ
Iterate over all values.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: u64,
}
fn main() -> Result<(), db_type::Error> {
let mut builder = DatabaseBuilder::new();
builder.define::<Data>()?;
let db = builder.create_in_memory()?;
// Open a read transaction
let r = db.r_transaction()?;
// Get all values
let _values: Vec<Data> = r.scan().primary()?.all().collect();
Ok(())
}
Sourcepub fn range<TR: InnerKeyValue, R: RangeBounds<TR>>(
&self,
range: R,
) -> PrimaryScanIterator<'_, T> ⓘ
pub fn range<TR: InnerKeyValue, R: RangeBounds<TR>>( &self, range: R, ) -> PrimaryScanIterator<'_, T> ⓘ
Iterate over all values in a range.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: u64,
}
fn main() -> Result<(), db_type::Error> {
let mut builder = DatabaseBuilder::new();
builder.define::<Data>()?;
let db = builder.create_in_memory()?;
// Open a read transaction
let r = db.r_transaction()?;
// Get the values from 5 to the end
let _values: Vec<Data> = r.scan().primary()?.range(5u64..).collect();
Ok(())
}
Sourcepub fn start_with<'a>(
&'a self,
start_with: impl InnerKeyValue + 'a,
) -> PrimaryScanIteratorStartWith<'a, T> ⓘ
pub fn start_with<'a>( &'a self, start_with: impl InnerKeyValue + 'a, ) -> PrimaryScanIteratorStartWith<'a, T> ⓘ
Iterate over all values starting with a prefix.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: String,
}
fn main() -> Result<(), db_type::Error> {
let mut builder = DatabaseBuilder::new();
builder.define::<Data>()?;
let db = builder.create_in_memory()?;
// Open a read transaction
let r = db.r_transaction()?;
// Get the values starting with "victor"
let _values: Vec<Data> = r.scan().primary()?.start_with("victor").collect();
Ok(())
}
Auto Trait Implementations§
impl<PrimaryTable, T> Freeze for PrimaryScan<PrimaryTable, T>where
PrimaryTable: Freeze,
impl<PrimaryTable, T> RefUnwindSafe for PrimaryScan<PrimaryTable, T>where
PrimaryTable: RefUnwindSafe,
T: RefUnwindSafe,
impl<PrimaryTable, T> Send for PrimaryScan<PrimaryTable, T>
impl<PrimaryTable, T> Sync for PrimaryScan<PrimaryTable, T>
impl<PrimaryTable, T> Unpin for PrimaryScan<PrimaryTable, T>
impl<PrimaryTable, T> UnwindSafe for PrimaryScan<PrimaryTable, T>where
PrimaryTable: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more