Trait bonsaidb::core::schema::Schema

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§

fn schema_name() -> SchemaName

Returns the unique SchemaName for this schema.

fn define_collections(schema: &mut Schematic) -> Result<(), Error>

Defines the Collections into schema.

Provided Methods§

fn schematic() -> Result<Schematic, Error>

Retrieves the Schematic for this schema.

Implementations on Foreign Types§

§

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.

Implementors§

§

impl Schema for Admin

§

impl Schema for BasicSchema

source§

impl<Config> Schema for FilesSchema<Config>where Config: FileConfig,

§

impl<T> Schema for Twhere T: Collection + 'static,