pub struct SecondaryScan<PrimaryTable, SecondaryTable, T: ToInput>where
PrimaryTable: ReadableTable<Key, &'static [u8]>,
SecondaryTable: ReadableMultimapTable<Key, Key>,{ /* private fields */ }Expand description
Scan values from the database by secondary key.
Implementations§
Source§impl<PrimaryTable, SecondaryTable, T: ToInput> SecondaryScan<PrimaryTable, SecondaryTable, T>where
PrimaryTable: ReadableTable<Key, &'static [u8]>,
SecondaryTable: ReadableMultimapTable<Key, Key>,
impl<PrimaryTable, SecondaryTable, T: ToInput> SecondaryScan<PrimaryTable, SecondaryTable, T>where
PrimaryTable: ReadableTable<Key, &'static [u8]>,
SecondaryTable: ReadableMultimapTable<Key, Key>,
Sourcepub fn all(&self) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
pub fn all(&self) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
Iterate over all values by secondary key.
If the secondary key is optional you will
get all values that have the secondary key set.
Anatomy of a secondary key it is a enum with the following structure: <table_name>Key::<name>.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
use itertools::Itertools;
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: u64,
#[secondary_key(optional)]
name: Option<String>,
}
fn main() -> Result<(), db_type::Error> {
let mut models = Models::new();
models.define::<Data>()?;
let db = Builder::new().create_in_memory(&models)?;
// Open a read transaction
let r = db.r_transaction()?;
// Get only values that have the secondary key set (name is not None)
let _values: Vec<Data> = r.scan().secondary(DataKey::name)?.all()?.try_collect()?;
Ok(())
}Sourcepub fn range<R: RangeBounds<impl ToKey>>(
&self,
range: R,
) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
pub fn range<R: RangeBounds<impl ToKey>>( &self, range: R, ) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
Iterate over all values by secondary key.
Anatomy of a secondary key it is a enum with the following structure: <table_name>Key::<name>.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
use itertools::Itertools;
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: u64,
#[secondary_key]
name: String,
}
fn main() -> Result<(), db_type::Error> {
let mut models = Models::new();
models.define::<Data>()?;
let db = Builder::new().create_in_memory(&models)?;
// Open a read transaction
let r = db.r_transaction()?;
// Get only values that have the secondary key name from C to the end
let _values: Vec<Data> = r.scan().secondary(DataKey::name)?.range("C"..)?.try_collect()?;
Ok(())
}Sourcepub fn start_with(
&self,
start_with: impl ToKey,
) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
pub fn start_with( &self, start_with: impl ToKey, ) -> Result<SecondaryScanIterator<'_, PrimaryTable, T>>
Iterate over all values by secondary key.
Anatomy of a secondary key it is a enum with the following structure: <table_name>Key::<name>.
§Example
use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
use itertools::Itertools;
#[derive(Serialize, Deserialize)]
#[native_model(id=1, version=1)]
#[native_db]
struct Data {
#[primary_key]
id: u64,
#[secondary_key]
name: String,
}
fn main() -> Result<(), db_type::Error> {
let mut models = Models::new();
models.define::<Data>()?;
let db = Builder::new().create_in_memory(&models)?;
// Open a read transaction
let r = db.r_transaction()?;
// Get only values that have the secondary key name starting with "hello"
let _values: Vec<Data> = r.scan().secondary(DataKey::name)?.start_with("hello")?.try_collect()?;
Ok(())
}Auto Trait Implementations§
impl<PrimaryTable, SecondaryTable, T> Freeze for SecondaryScan<PrimaryTable, SecondaryTable, T>
impl<PrimaryTable, SecondaryTable, T> RefUnwindSafe for SecondaryScan<PrimaryTable, SecondaryTable, T>
impl<PrimaryTable, SecondaryTable, T> Send for SecondaryScan<PrimaryTable, SecondaryTable, T>
impl<PrimaryTable, SecondaryTable, T> Sync for SecondaryScan<PrimaryTable, SecondaryTable, T>
impl<PrimaryTable, SecondaryTable, T> Unpin for SecondaryScan<PrimaryTable, SecondaryTable, T>
impl<PrimaryTable, SecondaryTable, T> UnwindSafe for SecondaryScan<PrimaryTable, SecondaryTable, T>
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