pub struct RowKey(/* private fields */);Expand description
The values of a key, to look a row up by: it can be hashed and sorted, and two are equal when their values are.
A whole number and a decimal are equal when they are the same number,
whatever its scale. So are a FLOAT and a DOUBLE, and a float equals no
decimal. Texts are equal when every character is, letter case included,
which a database’s own collation can see otherwise.
use std::collections::HashMap;
use sa17::{Columns, Database, RowId, RowKey};
let database = Database::open("garden.db")?;
let plants = database.table("plants")?;
for key in plants.definition().foreign_keys() {
let Some(target) = plants.target(key) else {
continue;
};
let named = Columns::at(target.definition(), key.target_positions())?;
let mut rows: HashMap<RowKey, RowId> = HashMap::new();
for row in target.scan(&named) {
let row = row?;
rows.extend(row.key().map(|key| (key, row.id())));
}
let naming = Columns::at(plants.definition(), key.positions())?;
for row in plants.scan(&naming) {
let row = row?;
let target = row.key().and_then(|key| rows.get(&key));
println!("{}: {target:?}", row.id());
}
}Implementations§
Trait Implementations§
impl Eq for RowKey
Source§impl Ord for RowKey
impl Ord for RowKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for RowKey
impl PartialOrd for RowKey
impl StructuralPartialEq for RowKey
Auto Trait Implementations§
impl Forget for RowKey
impl Freeze for RowKey
impl Move for RowKey
impl RefUnwindSafe for RowKey
impl Send for RowKey
impl Sync for RowKey
impl Unpin for RowKey
impl UnsafeUnpin for RowKey
impl UnwindSafe for RowKey
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