pub struct PointIndex<Tbl: Table, IndexType, Idx: Index> { /* private fields */ }Expand description
A handle to a Hash index on a table.
To get one of these from a ReducerContext, use:
ctx.db.{table}().{index}()for a table table and an index index.
Example:
use spacetimedb::{table, DbContext, PointIndex, ReducerContext};
#[table(accessor = user,
index(accessor = dogs_and_name, hash(columns = [dogs, name])))]
struct User {
id: u32,
name: String,
/// Number of dogs owned by the user.
dogs: u64
}
fn demo(ctx: &ReducerContext) {
let by_dogs_and_name: PointIndex<_, (u64, String), _> = ctx.db.user().dogs_and_name();
}For single-column indexes, use the name of the column:
use spacetimedb::{table, DbContext, RangedIndex, ReducerContext};
#[table(accessor = user)]
struct User {
id: u32,
username: String,
#[index(btree)]
dogs: u64
}
fn demo(ctx: &ReducerContext) {
let by_dogs: RangedIndex<_, (u64,), _> = ctx.db().user().dogs();
}Implementations§
Source§impl<Tbl: Table, IndexType, Idx: IndexIsPointed> PointIndex<Tbl, IndexType, Idx>
impl<Tbl: Table, IndexType, Idx: IndexIsPointed> PointIndex<Tbl, IndexType, Idx>
Sourcepub fn filter<P, K>(
&self,
point: P,
) -> impl Iterator<Item = Tbl::Row> + use<P, K, Tbl, IndexType, Idx>where
P: WithPointArg<K>,
pub fn filter<P, K>(
&self,
point: P,
) -> impl Iterator<Item = Tbl::Row> + use<P, K, Tbl, IndexType, Idx>where
P: WithPointArg<K>,
Returns an iterator over all rows in the database state
where the indexed column(s) equal point.
Unlike for ranged indices,
this method only accepts a point and not any prefix or range.
For example:
use spacetimedb::{table, ReducerContext, PointIndex};
#[table(accessor = user,
index(accessor = dogs_and_name, hash(columns = [dogs, name])))]
struct User {
id: u32,
name: String,
dogs: u64
}
fn demo(ctx: &ReducerContext) {
let by_dogs_and_name: PointIndex<_, (u64, String), _> = ctx.db.user().dogs_and_name();
// Find user with exactly 25 dogs and exactly the name "Joseph".
for user in by_dogs_and_name.filter((25u64, "Joseph")) {
/* ... */
}
// You can also pass arguments by reference if desired.
for user in by_dogs_and_name.filter((&25u64, &"Joseph".to_string())) {
/* ... */
}
}Sourcepub fn delete<P, K>(&self, point: P) -> u64where
P: WithPointArg<K>,
pub fn delete<P, K>(&self, point: P) -> u64where
P: WithPointArg<K>,
Deletes all rows in the database state
where the indexed column(s) equal point.
Unlike for ranged indices,
this method only accepts a point and not any prefix or range.
For example:
use spacetimedb::{table, ReducerContext, PointIndex};
#[table(accessor = user,
index(accessor = dogs_and_name, hash(columns = [dogs, name])))]
struct User {
id: u32,
name: String,
dogs: u64
}
fn demo(ctx: &ReducerContext) {
let by_dogs_and_name: PointIndex<_, (u64, String), _> = ctx.db.user().dogs_and_name();
// Delete users with exactly 25 dogs, and exactly the name "Joseph".
by_dogs_and_name.delete((25u64, "Joseph"));
// You can also pass arguments by reference if desired.
by_dogs_and_name.delete((&25u64, &"Joseph".to_string()));
}May panic if deleting any one of the rows would violate a constraint, though at present no such constraints exist.
Auto Trait Implementations§
impl<Tbl, IndexType, Idx> Freeze for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> RefUnwindSafe for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> Send for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> Sync for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> Unpin for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> UnsafeUnpin for PointIndex<Tbl, IndexType, Idx>
impl<Tbl, IndexType, Idx> UnwindSafe for PointIndex<Tbl, IndexType, Idx>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more