A small rust database that uses json in memory.

Related tags

Database tqdb
Overview

Rust Small Database (RSDB)

RSDB is a small library for creating a query-able database that is encoded with json.

The library is well tested (~96.30% coverage according to cargo-tarpaulin) and simple to use with the help of macros.

Examples

We can create a database using any type.

# use std::iter::FromIterator;
use rsdb::Database;
let db1: Database<i32> = Database::new();
let db2: Database<&u8> = Database::from_iter("hello world".as_bytes().into_iter());
struct Vec2 { x: i32, y: i32 };
let db3: Database<Vec2> = Database::from_iter(vec![ Vec2 { x: 0, y: 5 }, Vec2 { x: 100, y: 50 } ]);

If the type is serializable, we can even save it as json!

# use std::error::Error;
# use std::iter::FromIterator;
# fn main() -> Result<(), Box<dyn Error>> {
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Vec2 { x: i32, y: i32 };
 
use rsdb::Database;
let db1: Database<i32> = Database::new();
let db2: Database<&u8> = Database::from_iter("hello world".as_bytes().into_iter());
let db3: Database<Vec2> = Database::from_iter(vec![ Vec2 { x: 0, y: 5 }, Vec2 { x: 100, y: 50 } ]);
 
db1.save_to_file("db1.json")?;
db2.save_to_file("db2.json")?;
db3.save_to_file("db3.json")?;
# Ok(())
# }

We can query a database using macros!

We can search a database...

# use std::iter::FromIterator;
use rsdb::{Database, Query, search, search_mut, remove};
let db = Database::from_iter(1..10);
let found_items = search!(&db match |it: &i32| *it >= 5 && *it <= 7);

...search a database (with mutable access)

# use std::iter::FromIterator;
# use rsdb::{Database, Query, search, search_mut, remove};
# let mut db = Database::from_iter(1..10);
let found_items_mut1 = search_mut!(&mut db match |it: &i32| *it >= 5 && *it <= 7);
# std::mem::drop(found_items_mut1);
// or
let found_items_mut2 = search!(&mut db match |it: &i32| *it >= 5 && *it <= 7);

...and remove items easily!

# use std::iter::FromIterator;
# use rsdb::{Database, Query, search, search_mut, remove};
# let mut db = Database::from_iter(1..10);
let removed_items = remove!(&mut db match |it: &i32| *it >= 5 && *it <= 7);

If you don't want to use the macros, queries can be composed together like so:

# use std::iter::FromIterator;
use rsdb::{Database, Query};
let db = Database::from_iter(1..10);
// boring, simple query
db.search(Query::new(|it: &i32| *it < 5));
// cool AND query
db.search( Query::new(|it: &i32| *it < 5) & Query::new(|it: &i32| *it > 2) );
// cool OR query
db.search( Query::new(|it: &i32| *it >= 5) | Query::new(|it: &i32| *it <= 2) );
You might also like...
A cross-platform terminal database tool written in Rust
A cross-platform terminal database tool written in Rust

gobang is currently in alpha A cross-platform terminal database tool written in Rust Features Cross-platform support (macOS, Windows, Linux) Mu

Pure rust embeddable key-value store database.

MHdb is a pure Rust database implementation, based on dbm. See crate documentation. Changelog v1.0.3 Update Cargo.toml v1.0.2 Update Cargo.toml v1.0.1

influxdb provides an asynchronous Rust interface to an InfluxDB database.

influxdb influxdb provides an asynchronous Rust interface to an InfluxDB database. This crate supports insertion of strings already in the InfluxDB Li

FeOphant - A SQL database server written in Rust and inspired by PostreSQL.

A PostgreSQL inspired SQL database written in Rust.

GlueSQL is a SQL database library written in Rust

GlueSQL is a SQL database library written in Rust. It provides a parser (sqlparser-rs), execution layer, and optional storage (sled) packaged into a single library.

A pure Rust database implementation using an append-only B-Tree file format.

nebari nebari - noun - the surface roots that flare out from the base of a bonsai tree Warning: This crate is early in development. The format of the

PackDb is a simple messagepack based database in rust

PackDb is a simple key value messagepack store Inspired by kwik It uses your local storage

A prototype of a high-performance KV database built with Rust.
A prototype of a high-performance KV database built with Rust.

async-redis A prototype of a high-performance KV database built with Rust. Author: 3andero 11/10/2021 Overview The project starts as a fork of mini-re

cogo rust coroutine database driver (Mysql,Postgres,Sqlite)

cdbc Coroutine Database driver Connectivity.based on cogo High concurrency,based on coroutine No Future'q,Output=*,No async fn, No .await , no Poll*

Comments
  • publish crate

    publish crate

    • [x] match api guidelines at https://rust-lang.github.io/api-guidelines/
    • [x] make acct on crates.io
    • [x] create documentation
    • [x] cargo package
    • [x] cargo publish
    opened by KaceCottam 0
Owner
Kace Cottam
I am majoring in Computer Science BS at Washington State University, and minoring in Math and Japanese.
Kace Cottam
RisingWave is a cloud-native streaming database that uses SQL as the interface language.

RisingWave is a cloud-native streaming database that uses SQL as the interface language. It is designed to reduce the complexity and cost of building real-time applications. RisingWave consumes streaming data, performs continuous queries, and updates results dynamically. As a database system, RisingWave maintains results inside its own storage and allows users to access data efficiently.

Singularity Data 3.7k Jan 2, 2023
A fast and simple in-memory database with a key-value data model written in Rust

Segment Segment is a simple & fast in-memory database with a key-value data model written in Rust. Features Dynamic keyspaces Keyspace level control o

Segment 61 Jan 5, 2023
ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-text search.

ReefDB ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-

Sacha Arbonel 75 Jun 12, 2023
small distributed database protocol

clepsydra Overview This is a work-in-progress implementation of a core protocol for a minimalist distributed database. It strives to be as small and s

Graydon Hoare 19 Dec 2, 2021
SQL/JSON path engine in Rust.

sql-json-path SQL/JSON Path implementation in Rust. ?? Under development ?? Features Compatible with SQL/JSON Path standard and PostgreSQL implementat

RisingWave Labs 3 Nov 22, 2023
RedisJSON - a JSON data type for Redis

RedisJSON RedisJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating a

null 3.4k Jan 1, 2023
A user crud written in Rust, designed to connect to a MySQL database with full integration test coverage.

SQLX User CRUD Purpose This application demonstrates the how to implement a common design for CRUDs in, potentially, a system of microservices. The de

null 78 Nov 27, 2022
Rust version of the Haskell ERD tool. Translates a plain text description of a relational database schema to dot files representing an entity relation diagram.

erd-rs Rust CLI tool for creating entity-relationship diagrams from plain text markup. Based on erd (uses the same input format and output rendering).

Dave Challis 32 Jul 25, 2022
AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust

AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust. It is designed as an experimental engine for the TiKV project, and will bring aggressive optimizations for TiKV specifically.

TiKV Project 535 Jan 9, 2023
A programmable document database inspired by CouchDB written in Rust

PliantDB PliantDB aims to be a Rust-written, ACID-compliant, document-database inspired by CouchDB. While it is inspired by CouchDB, this project will

Khonsu Labs 718 Dec 31, 2022