Crates.io | airone |
lib.rs | airone |
version | 0.8.1 |
source | src |
created_at | 2022-08-30 14:31:15.298876 |
updated_at | 2024-05-28 21:55:42.491875 |
description | A Rust library which provides a simple in-memory, write-on-update database that is persisted to an append-only transaction file |
homepage | |
repository | https://gitlab.com/MassiminoilTrace/airone |
max_upload_size | |
id | 655169 |
size | 126,503 |
Airone is a Rust library which provides a simple in-memory, write-on-update database that is persisted to an append-only transaction file, inspired from Aral Balkan's JSDB.
In short, it acts as a Vec<T>
, but any change is automatically saved to file rapidly.
The name has nothing to do with "air" or "one", it simply comes from the Italian word "Airone", which means "Heron".
Hence, it has to be read [aiˈrone]
.
This library persists a list of structs from memory to disk. Every change in the data in memory is saved to disk automatically in a fast way, avoiding the full dump of the whole list.
AironeDb objects resemble simple arrays of structs, but they automatically save any change to disk under the hood. Here's an example:
let mut my_airone_array = AironeDb::<MyStruct>::new().unwrap();
my_airone_array.push( // <-- This command
MyStruct{field1: 5} // saves the new data to disk
); // automatically
my_airone_array
.get_mut(0).unwrap() // <-- Get a mutable proxy
// to the element at index 0
.set_field1(10); // <-- A setter method is generated automatically.
// The change is persisted to file.
println!("{}",
my_airone_array[0].field1 // you can access it by index
);
The Rust-to-C library bridge has been removed, in favour of a pure C library version, which is smaller, it simplifies the procmacro maintainability and is easier for you to include in any C-compatible project. You can find it at https://gitlab.com/MassiminoilTrace/airone_c.
Airone is developed to be used in situations where all of these prerequisites apply:
Here are two examples of good usage scenarios:
These limits can be a problem for some usage scenarios. Existing databases add all sort of optimizations, caching mechanisms and are very complex, in order to be able to deal with such big amount of data.
However, when the above-mentioned prerequisites apply, we can leverage these limits to simplify the source code, making it more maintanable and getting rid of all the bloatware.
Moreover, limiting object nesting makes it compatible with CSV style files, ensuring you can manipulate data with standard UNIX tools such as grep
and awk
.
Airone is aimed at helping small-tech to be produced, which is a way of building technology antithetical to the Silicon Valley model. Small-tech features close-to-zero data collection, a free and open source structure to achieve good transparency, no lust to scale exponentially, no desire in tracking people's behaviour while crunching tons of data and, overall, it has a goal to keep things simple and human.
The most basic usage example looks like this:
use airone::prelude::*;
#[derive(AironeDbDerive)]
struct Foo
{
pub field1: f64,
pub field2: String,
field3: Option<i32>
}
From this point, you can interact with a Vec of data of type Foo and automatically persist any change to file automatically.
let mut db: AironeDb<Foo> = AironeDb::new()?;
// Add an element
db.push(
struct Foo{field1: 0.0, field2: "Abc".to_string(), field3: None}
);
db.get(0); // <-- returns a read only Option<&Foo>
let m = db.get_mut(0).unwrap() // <-- returns a convenient
.set_field1(0.5); // writable wrapper of Foo
// in an Option<T>
// Remove element at index 0
db.remove(0);
Head to the official Documentation for the full usage instructions and implementation details.
This is NOT public domain, make sure to respect the license terms. You can find the license text in the COPYING file.
Copyright © 2022,2023,2024 Massimo Gismondi
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
This project uses some external libraries as described in the Cargo.toml
file.
This project is licensed using the license you can find in the COPYING file.