Drop-in embedded database

Overview

Struct DB πŸ”§ πŸ”©

All Contributors

Crates.io

Provides a drop-in, fast, and embedded database solution, focusing on maintaining coherence between Rust types and stored data with minimal boilerplate. It supports multiple indexes, real-time watch with filters, schema migration, enjoy 😌 πŸƒ .

Features

  • Fast as the storage engine you choose (redb, IndexDB planned*).
  • Embedded database (Linux, macOS, Windows, Android, iOS, WebBrowser WASM planned*).
  • Support multiple indexes (unique secondary keys).
  • Compatible with all Rust types (enum, struct, tuple etc.).
  • Query data (get, watch, iter etc.) using explicit type or type inference.
  • Real-time subscription with filters for insert, update and delete operations.
  • Schema migration using native Rust coercion.
  • Fully ACID-compliant transactions.
  • Add your own serialization/deserialization logic planned* (e.g: zero-copy).
  • Thread-safe.
  • Plus, all features depending on the storage engine you choose:
    • redb support: Linux, macOS, Windows, Android, iOS.
    • IndexDB support: WebBrowser (WASM) planned*.
    • Open an issue if you want to add another storage engine.

Status

Early development. Not ready for production.

How to use?

See docs.rs.

Example

use serde::{Deserialize, Serialize};
use struct_db::*;

#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[struct_db(
    fn_primary_key(p_key),  // required
    fn_secondary_key(s_key),  // optional
    // ... other fn_secondary_key ...
)]
struct Data(u32, String);

impl Data {
  // Returns primary key as big-endian bytes for consistent lexicographical ordering.
  pub fn p_key(&self) -> Vec<u8> {
    self.0.to_be_bytes().to_vec()
  }

  // Generates a secondary key combining the String field and the big-endian bytes of
  // the primary key for versatile queries.
  pub fn s_key(&self) -> Vec<u8> {
    let mut s_key = self.1.as_bytes().to_vec();
    s_key.extend_from_slice(&self.p_key().as_slice());
    s_key
  }
 }

 fn main() {
  let mut db = Db::init_tmp("my_db_example").unwrap();
  // Initialize the schema
  db.define::<Data>();

  // Insert data
  let txn = db.transaction().unwrap();
  {
    let mut tables = txn.tables();
    tables.insert(&txn, Data(1,"red".to_string())).unwrap();
    tables.insert(&txn, Data(2,"red".to_string())).unwrap();
    tables.insert(&txn, Data(3,"blue".to_string())).unwrap();
  }
  txn.commit().unwrap();
   
  let txn_read = db.read_transaction().unwrap();
  let mut tables = txn_read.tables();
   
  // Retrieve data with p_key=3 
  let retrieve_data: Data = tables.primary_get(&txn_read, &3_u32.to_be_bytes()).unwrap().unwrap();
  println!("data p_key='3' : {:?}", retrieve_data);
   
  // Iterate data with s_key="red" String
  for item in tables.secondary_iter_start_with::<Data>(&txn_read, DataKey::s_key, "red".as_bytes()).unwrap() {
    println!("data s_key='1': {:?}", item);
  }
   
  // Remove data
  let txn = db.transaction().unwrap();
  {
    let mut tables = txn.tables();
    tables.remove(&txn, retrieve_data).unwrap();
  }
  txn.commit().unwrap();
 }

Roadmap

The following features are planned before the 1.0 release

  • Stabilize the wording, if you have any suggestion follow this issue πŸ™ .
  • Add benchmarks tests.
  • Add documentation.
  • Stable release of redb or implement another stable storage engine(s) for Linux, macOS, Windows, Android, iOS.
  • Add support for IndexDB (WebBrowser).
  • Add support for custom serialization/deserialization logic.
  • Add CI for Linux, macOS, Windows, Android, iOS, WebBrowser.

Contributors

Akshith Madhur
Akshith Madhur

πŸ’»
You might also like...
Ector is an open source async, no-alloc actor framework for embedded devices

Ector is an open source async, no-alloc actor framework for embedded devices. Ector is an open source async, no-alloc actor framework for embedded dev

An embedded-hal driver for the TT21100 multi-touch touchscreen controller

tt21100 An embedded-hal driver for the TT21100 multi-touch touchscreen controller. If there is a feature which has not yet been implemented and which

Embedded-hal simulator.

hal-sim - embedded-hal Simulator (WIP - UNFINISHED) This crate simulates a small portion of the embedded-hal traits. Namely: GPIO ADC Additionally, it

Port of the fantastic Iconoir Icon Pack to Rust embedded devices, with a focus on speed, usability, and completeness.
Port of the fantastic Iconoir Icon Pack to Rust embedded devices, with a focus on speed, usability, and completeness.

embedded-iconoir - Icons for every device, ever. What is embedded-iconor? embedded-iconoir is a library that allows you to use Iconoir on embedded dev

A reactive runtime for embedded systems.

Actuate Examples A reactive diagram for robotics and control systems. Actuate leverages Rust's type system to create an efficient diagram that connect

A Distributed SQL Database - Building the Database in the Public to Learn Database Internals
A Distributed SQL Database - Building the Database in the Public to Learn Database Internals

Table of Contents Overview Usage TODO MVCC in entangleDB SQL Query Execution in entangleDB entangleDB Raft Consensus Engine What I am trying to build

A simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test.

sqlx-db-tester This a tool to test sqlx with postgres. It only supports tokio runtime at this moment. How to use it You should first create a TestDb d

Freebsd-embedded-hal - Like linux-embedded-hal but FreeBSD

freebsd-embedded-hal Implementation of embedded-hal traits for FreeBSD devices: gpio: using libgpio, with stateful and toggleable support, with suppor

A no_std GIF library for embedded applications(embedded-graphics)

tinygif A tiny gif decoder written in no_std Rust. This crate requires about 20kB of memory to decode a gif. basic decoding frame iterator interlace s

Super-lightweight Immediate-mode Embedded GUI framework, based on the awesome embedded-graphics library. Written in Rust.

Kolibri - A GUI framework made to be as lightweight as its namesake What is Kolibri? Kolibri is an embedded Immediate Mode GUI mini-framework very str

Embedded graph database

CQLite An embedded graph database implemented in Rust. This is currently a pre-release. It has not been extensively tested with 'real-world work-loads

Embedded graph database

CQLite An embedded graph database implemented in Rust. This is currently a pre-release. It has not been extensively tested with 'real-world work-loads

Scalable and encrypted embedded database with 3-tier caching

Infinitree is a versioned, embedded database that uses uniform, encrypted blobs to store data.

Embedded Distributed Encrypted Database (Research).

EDED Embedded Distributed Encrypted Database. Research projects to support ESSE. WIP Distributed design features Adapt to personal distributed usecase

Using embedded database modeled off SQLite - in Rust
Using embedded database modeled off SQLite - in Rust

Rust-SQLite (SQLRite) Rust-SQLite, aka SQLRite , is a simple embedded database modeled off SQLite, but developed with Rust. The goal is get a better u

A tiny embedded database built in Rust.
A tiny embedded database built in Rust.

TinyBase TinyBase is an in-memory database built with Rust, based on the sled embedded key-value store. It supports indexing and constraints, allowing

A lightweight, embedded key-value database for mobile clients (i.e., iOS, Android), written in Rust.

A lightweight, embedded key-value database for mobile clients (i.e., iOS, Android), written in Rust. ⚠️ Still in testing, not yet ready for production

An embedded, in-memory, immutable, copy-on-write, key-value database engine

An embedded, in-memory, immutable, copy-on-write, key-value database engine. Features In-memory database Multi-version concurrency control Rich transa

Kepler is a vulnerability database and lookup store and API currently utilising National Vulnerability Database and NPM Advisories as data sources
Kepler is a vulnerability database and lookup store and API currently utilising National Vulnerability Database and NPM Advisories as data sources

Kepler β€” Kepler is a vulnerability database and lookup store and API currently utilising National Vulnerability Database and NPM Advisories as data so

Comments
  • feat: Created HttpServer get endpoint and an example

    feat: Created HttpServer get endpoint and an example

    This is the flow I am following ,if you are ok with it I will implement the remaining part. If you need any changes let me know. This will just work on a single struct for now once I implement the entire CRUD functionality I'll implement for multiple struct.

    resolves issue #3

    opened by elliot14A 2
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • Cargo.toml (cargo)
    • struct_db_macro/Cargo.toml (cargo)
    • .github/workflows/build_and_test.yml (github-actions)
    • .github/workflows/conventional_commits.yml (github-actions)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • Use semantic commit type fix for dependencies and chore for all others if semantic commits are in use.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • Apply crowd-sourced package replacement rules.
    • Apply crowd-sourced workarounds for known problems with packages.

    πŸ”‘ Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 2 Pull Requests:

    fix(deps): update rust crate redb to 0.18.0
    • Schedule: ["at any time"]
    • Branch name: renovate/redb-0.x
    • Merge into: main
    • Upgrade redb to 0.18.0
    chore(deps): update actions/checkout action to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/actions-checkout-3.x
    • Merge into: main
    • Upgrade actions/checkout to v3

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Wording suggestions

    Wording suggestions

    Doubt about wording:

    • key vs index
    • primary_*
    • secondary_*
    • watch_*
    • transaction vs write_transaction vs read_write_transaction vs rw_transaction
    • read_transaction vs read_only_transaction vs r_transaction
    opened by vincent-herlemont 0
Owner
Vincent Herlemont
Vincent Herlemont
Drop ownership from "method position"

disown Drop ownership from "method position". Motivation Normally, unowned data is automatically dropped at the end of its residing block. We can also

Colin Woodbury 2 Mar 9, 2022
messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code. Goals Al

null 11 Dec 10, 2022
A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities.

utiles utiles = utils + tiles A mostly drop-in replacement for mercantile written w/ rust, plus several other util(e)ities. Installation pip install u

jesse 5 Jun 20, 2023
Crate of GitHub’s collection of gitignores, embedded, automatically updated

Gitignores GitHub’s collection of gitignores, embedded, automatically updated. API documentation. Public Domain via CC0-1.0 (same as source data). MSR

null 3 May 3, 2022
C API to SpringQL (for embedded mode)

SpringQL C Client This repository is a C client for SpringQL and provides it provides: springql.h: C header file. libspringql_client.{so,dylib}: Share

SpringQL 4 Jun 8, 2022
An asynchronous Hardware Abstraction Layer (HAL) for embedded systems

embedded-hal-async An asynchronous Hardware Abstraction Layer (HAL) for embedded systems. This crate contains asynchronous versions of the embedded-ha

Diego Barrios Romero 3 Jan 22, 2022
A compatibility layer to smooth the transition between different versions of embedded-hal

Embedded HAL Compatibility Layer A compatibility layer to smooth the transition between different versions of embedded-hal (specifically 0.2.x and 1.0

Ryan 7 Sep 11, 2022
βš™οΈ Crate to discover embedded programming with uno r3 project

βš™οΈ Crate to discover embedded programming with uno r3 project

null 0 Feb 3, 2022
diff successive buffers with embedded ansi codes in rust, outputting a minimal change

ansi-diff diff successive buffers with embedded ansi codes in rust, outputting a minimal change You can use this crate to build command-line interface

James Halliday 7 Aug 11, 2022
TI LDC1312/LDC1314/LDC1612/LDC1614 inductance-to-digital converter driver for Rust embedded-hal

ldc1x1x Rust embedded-hal 1.x driver for Texas Instruments (TI) IΒ²C inductance-to-digital converters (LDC): LDC1312/LDC1314, LDC1612/LDC1614. Includes

null 2 Oct 2, 2022