koit

Crates.iokoit
lib.rskoit
version0.2.0
sourcesrc
created_at2020-11-30 21:48:59.0648
updated_at2021-05-13 14:40:53.31784
descriptionA simple, asynchronous, pure-Rust, structured, embedded database
homepage
repositoryhttps://github.com/tomcur/koit
max_upload_size
id318389
size25,469
Tom Churchman (tomcur)

documentation

README

Koit

Crates.io MIT licensed

Koit is a simple, asynchronous, pure-Rust, structured, embedded database.

[dependencies]
koit = "0.2"

Example

use std::default::Default;

use koit::{FileDatabase, format::Json};
use serde::{Deserialize, Serialize};

#[derive(Default, Deserialize, Serialize)]
struct Data {
    cats: u64,
    yaks: u64,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = FileDatabase::<Data, Json>::load_from_path_or_default("./db.json").await?;
  
    db.write(|data| {
        data.cats = 10;
        data.yaks = 32;
    }).await;
    
    assert_eq!(db.read(|data| data.cats + data.yaks).await, 42);

    db.save().await?;

    Ok(())
}

Features

  • built-in, future-aware, reader-writer synchronization
  • works with arbitrary data formatters
  • works with arbitrary storage backends
  • comes with default formatters and backends that fit more purposes

By default, Koit comes with its file-backend, JSON formatter and Bincode formatter enabled. You can cherry-pick features instead.

[dependencies.koit]
version = "0.2"
default-features = false
features = ["bincode-format"]

Purpose

Koit enables quickly implementing persistence and concurrent access to structured data. It is meant to be used with relatively small amounts (megabytes) of data.

It is not a performant database. Upon loading, the entire data structure is kept in memory. Upon saving, the entire data structure is formatted and written to the storage backend.

Other crates

Koit is inspired by Rustbreak, a similar (synchronous) database.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Koit by you, shall be licensed as MIT, without any additional terms or conditions.

Commit count: 6

cargo fmt