This is a pure Rust port of UnQLite, an embedded, transactional, NoSQL database engine. This project aims to provide a safe and idiomatic Rust an alternative to the original C library.
Note: This is a work in progress and is not yet feature-complete. The core functionality is in place, but advanced features like cursors and full transaction support are still under development.
- Embedded, Zero-Configuration: No need for a separate server process. The database is stored in a single file.
- Transactional: ACID-compliant transactions ensure data integrity.
- Key/Value Store: A simple and fast key-value store.
- Document Store: Store and retrieve JSON documents.
First, add this to your Cargo.toml:
[dependencies]
unqlite-rs = { git = "https://github.com/symisc/unqlite" }
serde_json = "1.0"use unqlite_rs::Database;
fn main() -> std::io::Result<()> {
let mut db = Database::open_os("test_kv.db".as_ref())?;
let key = b"hello";
let value = b"world";
// Store a key-value pair
db.kv_store(key, value)?;
db.commit()?;
// Fetch the value
let fetched = db.kv_fetch(key)?.unwrap();
assert_eq!(fetched, value);
// Delete the key
db.kv_delete(key)?;
db.commit()?;
Ok(())
}use unqlite_rs::Database;
use serde_json::json;
fn main() -> std::io::Result<()> {
let mut db = Database::open_os("test_doc.db".as_ref())?;
let key = b"user:123";
let doc = json!({
"name": "Jules",
"email": "jules@example.com",
"is_admin": true
});
// Store a document
db.doc_store(key, &doc)?;
db.commit()?;
// Fetch the document
let fetched = db.doc_fetch(key)?.unwrap();
assert_eq!(fetched, doc);
Ok(())
}