All Projects → TheNeikos → Rustbreak

TheNeikos / Rustbreak

Licence: other
A simple, fast and easy to use self-contained single file storage for Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Rustbreak

Filebase
A Simple but Powerful Flat File Database Storage.
Stars: ✭ 235 (-25.4%)
Mutual labels:  database, storage
write-yaml
Basic node.js utility for converting JSON to YAML and writing formatting YAML files to disk.
Stars: ✭ 38 (-87.94%)
Mutual labels:  yaml, file
Aresdb
A GPU-powered real-time analytics storage and query engine.
Stars: ✭ 2,814 (+793.33%)
Mutual labels:  database, storage
Irmin
Built-in Snapshotting - backup and restore Storage Agnostic - you can use Irmin on top of your own storage layer Custom Datatypes - (de)serialization for custom data types, derivable via ppx_irmin Highly Portable - runs anywhere from Linux to web browsers and Xen unikernels Git Compatibility - irmin-git uses an on-disk format that can be inspected and modified using Git Dynamic Behavior - allows the users to define custom merge functions, use in-memory transactions (to keep track of reads as well as writes) and to define event-driven workflows using a notification mechanism
Stars: ✭ 1,524 (+383.81%)
Mutual labels:  database, storage
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-91.11%)
Mutual labels:  yaml, file
Combinefirebase
Combine wrapper on Google's iOS Firebase library.
Stars: ✭ 126 (-60%)
Mutual labels:  database, storage
Skiplist
Fast and easy-to-use skip list for Go.
Stars: ✭ 165 (-47.62%)
Mutual labels:  hashmap, database
Pufferdb
🐡 An Android & JVM key-value storage powered by Protobuf and Coroutines
Stars: ✭ 91 (-71.11%)
Mutual labels:  database, storage
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-88.25%)
Mutual labels:  storage, file
read-yaml
Very thin wrapper around js-yaml for directly reading in YAML files.
Stars: ✭ 25 (-92.06%)
Mutual labels:  yaml, file
Unqlite
An Embedded NoSQL, Transactional Database Engine
Stars: ✭ 1,583 (+402.54%)
Mutual labels:  database, storage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+840.32%)
Mutual labels:  database, storage
Bojack
🐴 The unreliable key-value store
Stars: ✭ 101 (-67.94%)
Mutual labels:  database, storage
Tera
An Internet-Scale Database.
Stars: ✭ 1,846 (+486.03%)
Mutual labels:  database, storage
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-71.11%)
Mutual labels:  database, file
Autoserver
Create a full-featured REST/GraphQL API from a configuration file
Stars: ✭ 188 (-40.32%)
Mutual labels:  yaml, database
Vault
Easy persistence of Contentful data for Android over SQLite.
Stars: ✭ 80 (-74.6%)
Mutual labels:  database, storage
React Native Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 9,674 (+2971.11%)
Mutual labels:  database, storage
SimpleStorage
💾 Simplify Android Storage Access Framework for file management across API levels.
Stars: ✭ 498 (+58.1%)
Mutual labels:  storage, file
Lazer Database
PHP flat file database to store data with JSON
Stars: ✭ 254 (-19.37%)
Mutual labels:  database, file

Rustbreak

Build Status Crates Link

Documentation

Rustbreak is an Daybreak inspired self-contained file database. It is meant to be fast and simple to use. You add it to your application and it should just work for you. The only thing you will have to take care of is saving.

When to use it

This library started out because of a need to be able to quickly write an application in rust that needed some persistence while still being able to write arbitrary data to it.

In Ruby there is Daybreak however for Rust there was no similar crate, until now!

When not to use it

Rustbreak makes several trade-offs to be easy to use and extend, so knowing of these drawbacks is important if you wish to use the library:

  • The Database needs to fit into memory (Rustbreak cannot do partial loads/saves, so if the Database exceeds your available memory you will run OOM)
  • Not all backends support atomic saves, so if your program crashes while it is saving you might save incomplete data (Notably only PathBackend supports atomic saves)

Features

  • Simple To Use, Fast, Secure
  • Threadsafe
  • Serde compatible storage (ron, bincode, or yaml included)

Quickstart

Add this to your Cargo.toml:

[dependencies.rustbreak]
version = "2"
features = ["ron_enc"] # You can also use "yaml_enc" or "bin_enc"
                       # Check the documentation to add your own!
extern crate rustbreak;
use std::collections::HashMap;
use rustbreak::{MemoryDatabase, deser::Ron};

fn main() -> rustbreak::Result<()> {
    let db = MemoryDatabase::<HashMap<u32, String>, Ron>::memory(HashMap::new())?;

    println!("Writing to Database");
    db.write(|db| {
        db.insert(0, String::from("world"));
        db.insert(1, String::from("bar"));
    });

    db.read(|db| {
        // db.insert("foo".into(), String::from("bar"));
        // The above line will not compile since we are only reading
        println!("Hello: {:?}", db.get(&0));
    })?;

    Ok(())
}

Usage

Usage is quite simple:

  • Create/open a database using one of the Database constructors:
    • Create a FileDatabase with FileDatabase::from_path.
    • Create a MemoryDatabase with MemoryDatabase::memory.
    • Create a MmapDatabase with MmapDatabase::mmap or MmapDatabase::mmap_with_size with mmap feature.
    • Create a Database with Database::from_parts.
  • Write/Read data from the Database
  • Don't forget to run save periodically, or whenever it makes sense.
    • You can save in parallel to using the Database. However you will lock write acess while it is being written to storage.
# use std::collections::HashMap;
use rustbreak::{MemoryDatabase, deser::Ron};

let db = MemoryDatabase::<HashMap<String, String>, Ron>::memory(HashMap::new(), Ron);

println!("Writing to Database");
db.write(|db| {
    db.insert("hello".into(), String::from("world"));
    db.insert("foo".into(), String::from("bar"));
});

db.read(|db| {
    // db.insert("foo".into(), String::from("bar"));
    // The above line will not compile since we are only reading
    println!("Hello: {:?}", db.get("hello"));
});

Encodings

The following parts explain how to enable the respective features. You can also enable several at the same time.

Yaml

If you would like to use yaml you need to specify yaml_enc as a feature:

[dependencies.rustbreak]
version = "1"
features = ["yaml_enc"]

You can now use rustbreak::deser::Yaml as deserialization struct.

Ron

If you would like to use ron you need to specify ron_enc as a feature:

[dependencies.rustbreak]
version = "1"
features = ["ron_enc"]

You can now use rustbreak::deser::Ron as deserialization struct.

Bincode

If you would like to use bincode you need to specify bin_enc as a feature:

[dependencies.rustbreak]
version = "1"
features = ["bin_enc"]

You can now use rustbreak::deser::Bincode as deserialization struct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].