9 unstable releases

0.5.2 Apr 29, 2023
0.5.1 Jan 8, 2023
0.4.1 Sep 11, 2022
0.4.0 Oct 4, 2021
0.1.0 Sep 14, 2019

#56 in Database implementations

37 downloads per month
Used in structsy_tools

MIT license

315KB
7.5K SLoC

Structsy

build status coverage report

Structsy is a simple, single file, embedded, struct database for rust, with support of transactions.

SCOPE

This project aim to show some innovative way to persist and query data with rust, providing at the same time a useful embeddable database for small rust projects.

REACH

Mastodon
Matrix Chat
https://www.structsy.rs

COMPILING THE SOURCE

Checkout the source code:

git clone https://gitlab.com/tglman/structsy.git

Compile and Test

cargo test 

INSTALL

Add it as dependency of your project:

[dependencies]
structsy="0.4"

USAGE EXAMPLE

Persist a simple struct.

use structsy::{Structsy, StructsyError, StructsyTx};
use structsy_derive::{queries, Persistent};

#[derive(Persistent, Debug, PartialEq)]
struct MyData {
    #[index(mode = "cluster")]
    name: String,
    address: String,
}

#[queries(MyData)]
trait MyDataQuery {
    /// The parameters name have two match the field names and type
    /// like the `address` parameter match the `address` field of the struct.
    fn search(self, address: String) -> Self;
}

fn main() -> Result<(), StructsyError> {
    let db = Structsy::open("example_basic_query.db")?;
    db.define::<MyData>()?;

    let my_data = MyData {
        name: "Structsy".to_string(),
        address: "https://gitlab.com/tglman/structsy".to_string(),
    };
    let mut tx = db.begin()?;
    let _id = tx.insert(&my_data)?;
    tx.commit()?;

    let to_find = "https://gitlab.com/tglman/structsy".to_string();
    let mut iter = db.query::<MyData>().search(to_find.clone()).into_iter();
    let (_id, data) = iter.next().unwrap();
    assert_eq!(data.address, to_find);

    Ok(())
}

Dependencies

~1.7–2.7MB
~54K SLoC