1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
pub mod schema;
pub use schema::*;
use crate::indexer::{errors::LoadIndexerError, Indexer};
use uuid::Uuid;
#[derive(Debug)]
pub struct Collection {
pub id: Uuid,
pub name: String,
pub collection_ref: Vec<u8>,
pub indexer: Indexer,
}
impl Collection {
pub fn first_schema_version(&self) -> u32 {
0
}
pub fn last_schema_version(&self) -> u32 {
0
}
#[cfg(test)]
pub fn new_test_collection() -> Self {
use crate::{
decoder::{DataType, RecordSchema},
utils::collection,
};
use uuid::uuid;
Self {
id: uuid!("11111111-1111-1111-1111-111111111111"),
name: "Test Collection".into(),
collection_ref: vec![1, 2, 3, 4, 5, 6, 7, 8],
indexer: Indexer::new(
Default::default(),
RecordSchema {
map: collection! {
"title" => DataType::String,
"year" => DataType::Uint64
},
},
),
}
}
}
impl TryFrom<AnnotatedCollectionSchema> for Collection {
type Error = LoadIndexerError;
fn try_from(value: AnnotatedCollectionSchema) -> Result<Self, Self::Error> {
let AnnotatedCollectionSchema {
id,
name,
collection_ref,
schema,
} = value;
Ok(Self {
id,
name,
collection_ref,
indexer: schema.try_into()?,
})
}
}