mod collection;
mod names;
mod schematic;
mod summary;
pub mod view;
pub use bonsaidb_macros::{Collection, Schema, View, ViewSchema};
pub use self::collection::{
AsyncEntry, AsyncList, Collection, DefaultSerialization, InsertError, List, Nameable,
NamedCollection, NamedReference, SerializedCollection,
};
pub use self::names::{
Authority, CollectionName, InvalidNameError, Name, Qualified, QualifiedName, SchemaName,
ViewName,
};
pub use self::schematic::Schematic;
pub use self::summary::{CollectionSummary, SchemaSummary, ViewSummary};
pub use self::view::map::{Map, MappedValue, ViewMappedValue};
pub use self::view::{
CollectionMapReduce, DefaultViewSerialization, MapReduce, ReduceResult, SerializedView, View,
ViewMapResult, ViewSchema,
};
use crate::Error;
pub trait Schema: Send + Sync + 'static {
fn schema_name() -> SchemaName;
fn define_collections(schema: &mut Schematic) -> Result<(), Error>;
fn schematic() -> Result<Schematic, Error> {
Schematic::from_schema::<Self>()
}
}
impl Schema for () {
fn schema_name() -> SchemaName {
SchemaName::new("", "")
}
fn define_collections(_schema: &mut Schematic) -> Result<(), Error> {
Ok(())
}
}
impl<T> Schema for T
where
T: Collection + 'static,
{
fn schema_name() -> SchemaName {
SchemaName::from(Self::collection_name())
}
fn define_collections(schema: &mut Schematic) -> Result<(), Error> {
schema.define_collection::<Self>()
}
}