Lightweight embedded database

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

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

Key features

Usage example

```rust extern crate serde;

[macro_use]

extern crate serde_derive; // This allows inserting JSON documents

[macro_use]

extern crate serde_json;

[macro_use]

extern crate ledb; // This allows define typed documents easy

[macro_use]

extern crate ledbderive; extern crate ledbtypes;

use ledb::{Options, Storage, IndexKind, KeyType, Filter, Comp, Order, OrderKind, Primary};

[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Document)]

struct MyDoc { #[document(primary)] id: Option, title: String, tag: Vec, timestamp: u32, }

fn main() { let dbpath = ".testdbs/mytempdb"; let _ = std::fs::removedirall(&db_path);

// Open storage
let storage = Storage::new(&db_path, Options::default()).unwrap();

// Get collection
let collection = storage.collection("my-docs").unwrap();

// Ensure indexes
query!(index for collection
    title str unique,
    tag str,
    timestamp int unique,
).unwrap();

// Insert JSON document
let first_id = query!(insert into collection {
    "title": "First title",
    "tag": ["some tag", "other tag"],
    "timestamp": 1234567890,
}).unwrap();

// Insert typed document
let second_id = collection.insert(&MyDoc {
    title: "Second title".into(),
    tag: vec![],
    timestamp: 1234567657,
}).unwrap();

// Find documents
let found_docs = query!(
    find MyDoc in collection
    where title == "First title"
).unwrap().collect::<Result<Vec<_>, _>>().unwrap();

// Update documents
let n_affected = query!(
    update in collection modify title = "Other title"
    where title == "First title"
).unwrap();

// Find documents with descending ordering
let found_docs = query!(
    find MyDoc in collection order desc
).unwrap().collect::<Result<Vec<_>, _>>().unwrap();

// Remove documents
let n_affected = query!(
    remove from collection where title == "Other title"
).unwrap();

} ```