3 releases (breaking)

0.4.0 Jun 11, 2020
0.3.0 Sep 6, 2019
0.2.0 Oct 27, 2018

#2362 in Database interfaces

Download history 3/week @ 2024-02-19 32/week @ 2024-02-26 2/week @ 2024-03-04 4/week @ 2024-03-11 8/week @ 2024-03-25 65/week @ 2024-04-01

78 downloads per month
Used in 3 crates

MIT license

25KB
677 lines

Types for defining storable documents

License: MIT Travis-CI Build Status Appveyor Build status Crates.io Package Docs.rs API Documentation

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.

Usage example

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))
    }
}

Dependencies

~0.4–1.3MB
~29K SLoC