Trait bonsaidb_core::schema::Schema
source · pub trait Schema: Send + Sync + 'static {
// Required methods
fn schema_name() -> SchemaName;
fn define_collections(schema: &mut Schematic) -> Result<(), Error>;
// Provided method
fn schematic() -> Result<Schematic, Error> { ... }
}
Expand description
Defines a group of collections that are stored into a single database.
Deriving this trait
This trait can be derived rather than manually implemented:
use bonsaidb_core::schema::{Collection, Schema};
use serde::{Deserialize, Serialize};
#[derive(Schema)]
#[schema(name = "MySchema", collections = [MyCollection])]
pub struct MySchema;
#[derive(Serialize, Deserialize, Default, Collection)]
#[collection(name = "MyCollection")]
pub struct MyCollection {
pub rank: u32,
pub score: f32,
}
If you’re publishing a schema for use in multiple projects, consider giving
the schema an authority
, which gives your schema a namespace:
use bonsaidb_core::schema::Schema;
#[derive(Schema)]
#[schema(name = "MySchema", authority = "khonsulabs", collections = [MyCollection])]
pub struct MySchema;
Required Methods§
sourcefn schema_name() -> SchemaName
fn schema_name() -> SchemaName
Returns the unique SchemaName
for this schema.
Provided Methods§
Implementations on Foreign Types§
source§impl Schema for ()
impl Schema for ()
This implementation is for accessing databases when interacting with collections isn’t required. For example, accessing only the key-value store or pubsub.