2 releases

0.2.1 May 20, 2021
0.2.0 May 20, 2021

#188 in Database implementations

Download history 139/week @ 2024-07-29 58/week @ 2024-08-05 66/week @ 2024-08-12 14/week @ 2024-08-19 121/week @ 2024-08-26 142/week @ 2024-09-02 315/week @ 2024-09-09 274/week @ 2024-09-16 422/week @ 2024-09-23 354/week @ 2024-09-30 684/week @ 2024-10-07 284/week @ 2024-10-14 638/week @ 2024-10-21 155/week @ 2024-10-28 518/week @ 2024-11-04 378/week @ 2024-11-11

1,702 downloads per month
Used in rmw

MIT license

24KB
328 lines

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::Toml};
use serde::{Deserialize, Serialize};

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

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = FileDatabase::<Data, Toml>::load_from_path_or_default("./db.toml").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 / Toml formatter and Bincode formatter enabled. You can cherry-pick features instead.

[dependencies.koit]
version = "0.2"
default-features = false
features = ["toml-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.

Dependencies

~6–15MB
~209K SLoC