Types for defining storable documents
This types and traits widely used for documents which can be managed using persistent storages like LEDB.
The LEDB is an attempt to implement simple but efficient, lightweight but powerful document storage.
The abbreviation LEDB may be treated as an Lightweight Embedded DB, also Low End DB, also Literium Engine DB, also LitE DB, and so on.
Links
Usage example
use serde::{Serialize, Deserialize};
use ledb_types::{Document, Identifier, Primary, KeyFields, KeyType, IndexKind};
#[derive(Serialize, Deserialize)]
struct MyDoc {
id: Option<Primary>,
title: String,
tag: Vec<String>,
timestamp: u32,
meta: MetaData,
}
#[derive(Serialize, Deserialize)]
struct MetaData {
keywords: Vec<String>,
description: String,
}
impl Document for MyDoc {
fn primary_field() -> Identifier {
"id".into()
}
fn key_fields() -> KeyFields {
KeyFields::new()
.with_field(("title", KeyType::String, IndexKind::Unique))
.with_field(("tag", KeyType::String, IndexKind::Index))
.with_field(("timestamp", KeyType::Int, IndexKind::Unique))
.with_fields(MetaData::key_fields().with_parent("meta"))
}
}
impl Document for MetaData {
fn key_fields() -> KeyFields {
KeyFields::new()
.with_field(("keywords", KeyType::String, IndexKind::Index))
}
}