Crates.io | ledb-types |
lib.rs | ledb-types |
version | 0.4.0 |
source | src |
created_at | 2018-10-27 14:51:15.431521 |
updated_at | 2020-06-11 16:53:12.418529 |
description | Basic types for storable documents |
homepage | https://github.com/katyo/ledb/tree/master/ledb-types |
repository | https://github.com/katyo/ledb |
max_upload_size | |
id | 92909 |
size | 24,298 |
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.
use serde::{Serialize, Deserialize};
use ledb_types::{Document, Identifier, Primary, KeyFields, KeyType, IndexKind};
#[derive(Serialize, Deserialize)]
struct MyDoc {
// define optional primary key field
id: Option<Primary>,
// define other fields
title: String,
tag: Vec<String>,
timestamp: u32,
// define nested document
meta: MetaData,
}
#[derive(Serialize, Deserialize)]
struct MetaData {
// define index field
keywords: Vec<String>,
// define other fields
description: String,
}
impl Document for MyDoc {
// declare primary key field name
fn primary_field() -> Identifier {
"id".into()
}
// declare other key fields
fn key_fields() -> KeyFields {
KeyFields::new()
// add key fields of document
.with_field(("title", KeyType::String, IndexKind::Unique))
.with_field(("tag", KeyType::String, IndexKind::Index))
.with_field(("timestamp", KeyType::Int, IndexKind::Unique))
// add key fields from nested document
.with_fields(MetaData::key_fields().with_parent("meta"))
}
}
impl Document for MetaData {
// declare key fields for index
fn key_fields() -> KeyFields {
KeyFields::new()
// add key fields of document
.with_field(("keywords", KeyType::String, IndexKind::Index))
}
}