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

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

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

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

            
34
impl NamedCollection for Database {
35
    type ByNameView = ByName;
36
}