Hey, I am struggling to make MultiIndex work the way I need, maybe it's not possible at all at this stage. Hope to get some advice.
Basically I have a primary key which is a tuple (Addr, String) and additional index collection which is a String. I need to be able to query by secondary index(by collection) and do filtering and pagination by primary key.
I can do this with two maps: Primary: Map<(Addr, String), Value> + SecondaryIndex: Map<(String, (Addr, String)), Empty> and then I can do something like this:
SecondaryIndex
.prefix(collection)
.keys(...)
.filter(|(_, (addr, s)| addr == filter_addr)
.take(1)
.map(|(_, (addr, s) Primary.prefix(addr).range(Bound(s), None).map(// do something with result)
This is probably doable but not very efficient and hard to maintain I would like to do something:
get_indexed_map()
.idx.collection.prefix(collection)
// here I would like to prefix primary key with filter_addr and then call range to do pagination
.range(
deps.storage,
Bound(s),
None,
Order::Ascending,
pub struct ExtraIndexes<'a> {
// pk goes to second tuple element
pub collection: MultiIndex<'a, (String, Vec<u8>), Value>,
}
get_indexed_map() -> IndexedMap<'a, (Addr, String), Value, ExtraIndexes<'a>>
Any advice is appreciated.
Hey, I am struggling to make
MultiIndexwork the way I need, maybe it's not possible at all at this stage. Hope to get some advice.Basically I have a primary key which is a tuple
(Addr, String)and additional indexcollectionwhich is aString. I need to be able to query by secondary index(by collection) and do filtering and pagination by primary key.I can do this with two maps:
Primary: Map<(Addr, String), Value>+SecondaryIndex: Map<(String, (Addr, String)), Empty>and then I can do something like this:This is probably doable but not very efficient and hard to maintain I would like to do something:
Any advice is appreciated.