1
use serde::{Deserialize, Serialize};
2

            
3
use crate::define_basic_unique_mapped_view;
4
use crate::document::{CollectionDocument, Emit};
5
use crate::schema::{Collection, NamedCollection, SchemaName};
6

            
7
/// A database stored in BonsaiDb.
8
249800
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Collection)]
9
#[collection(authority = "bonsaidb", name = "databases", views = [ByName], core = crate)]
10
pub struct Database {
11
    /// The name of the database.
12
    pub name: String,
13
    /// The schema defining the database.
14
    pub schema: SchemaName,
15
}
16

            
17
define_basic_unique_mapped_view!(
18
    ByName,
19
    Database,
20
    1,
21
    "by-name",
22
    String,
23
    SchemaName,
24
49960
    |document: CollectionDocument<Database>| {
25
49960
        document
26
49960
            .header
27
49960
            .emit_key_and_value(document.contents.name, document.contents.schema)
28
49960
    },
29
);
30

            
31
impl NamedCollection for Database {
32
    type ByNameView = ByName;
33
}