Trait bonsaidb_core::schema::view::CollectionViewSchema
source · [−]pub trait CollectionViewSchema: Send + Sync + Debug + 'static where
<Self::View as View>::Collection: SerializedCollection, {
type View: SerializedView;
fn map(
&self,
document: CollectionDocument<<Self::View as View>::Collection>
) -> ViewMapResult<Self::View>;
fn unique(&self) -> bool { ... }
fn version(&self) -> u64 { ... }
fn reduce(
&self,
mappings: &[ViewMappedValue<Self::View>],
rereduce: bool
) -> ReduceResult<Self::View> { ... }
}Expand description
A View for a Collection that stores Serde-compatible documents. The
only difference between implmementing this and View is that the map
function receives a CollectionDocument instead of a BorrowedDocument.
Associated Types
type View: SerializedView
type View: SerializedView
The view this schema is an implementation of.
Required methods
fn map(
&self,
document: CollectionDocument<<Self::View as View>::Collection>
) -> ViewMapResult<Self::View>
fn map(
&self,
document: CollectionDocument<<Self::View as View>::Collection>
) -> ViewMapResult<Self::View>
The map function for this view. This function is responsible for emitting entries for any documents that should be contained in this View. If None is returned, the View will not include the document.
Provided methods
If true, no two documents may emit the same key. Unique views are
updated when the document is saved, allowing for this check to be done
atomically. When a document is updated, all unique views will be
updated, and if any of them fail, the document will not be allowed to
update and an
Error::UniqueKeyViolation will be
returned.
The version of the view. Changing this value will cause indexes to be rebuilt.
fn reduce(
&self,
mappings: &[ViewMappedValue<Self::View>],
rereduce: bool
) -> ReduceResult<Self::View>
fn reduce(
&self,
mappings: &[ViewMappedValue<Self::View>],
rereduce: bool
) -> ReduceResult<Self::View>
The reduce function for this view. If Err(Error::ReduceUnimplemented)
is returned, queries that ask for a reduce operation will return an
error. See CouchDB’s Reduce/Rereduce
documentation
for the design this implementation will be inspired by