1 unstable release

0.1.0 Apr 18, 2020

#115 in #delete

32 downloads per month
Used in 2 crates

MPL-2.0 license

3KB

smoldb

An extremely experimental abstract database interface over SQLite, designed to allow type-safe NoSQL-like* storage of serde compatible objects with indexing, without needing to write any SQL.

*you can't actually search arbitrary documents, you have to decide on what to index up front. however, you can store arbitrary documents which might be enough for some applications.

This consists of a set of traits in smoldb_traits and a set of proc macros in smoldb_derive, with everything conveniently re-exported in the top-level smoldb crate.

Check out the example for a working example.

Features

  • SQL Basics
    • Insert
    • Select
    • Update
    • Delete
  • Extended types (as it stands, everything is strings)
    • Integers
    • Strings
    • Blobs

TODOs

  • Clean up / split macros
  • Make Store impl generic over Storage types
  • Genericise over serde encoder/decoder
  • Fix Index types to use &str and &[u8] in place of String and Vec<u8> respectively

Usage

First, define a type that is serializable and derives from Smoldb. The #[index] macro specifies that you would like to be able to search for objects using this index. Note that any inexable types must implement ToSql.


#[derive(Clone, Debug, PartialEq, Smoldb, Serialize, Deserialize)]
pub struct User {
  #[index]
  pub id: isize,

  #[index]
  pub name: String,

  pub email: String,

  pub description: String,
}

You can then interact with objects using the Store traits. Note that some methods require the fully qualified trait syntax to provide type information (usually where you're not passing an object in already).

Dependencies

~22MB
~424K SLoC