sqjson 0.1.9

A simple JSON-based embedded database
Documentation
//! Embedded file-based JSON database engine using memory-mapped files.
//!
//! # sqjson
//!
//! `sqjson` is a lightweight, embedded, file-based key-value database written in Rust.
//! It stores structured data as JSON values and uses memory-mapped I/O for efficient read/write access.
//!
//! Inspired by SQLite, but minimal and JSON-native, with an emphasis on simplicity and portability.
//!
//! ## Features
//!
//! - Embedded, single-file storage (`.db` file)
//! - Efficient memory-mapped I/O for fast reads/writes
//! - JSON value storage using `serde_json`
//! - String-keyed key-value API: `put`, `get`, `delete`, `flush`
//! - Field-level access: `get_field(key, field)`
//! - Secondary indexes for fast field-based queries: `query(field, value)`
//! - Range queries for numeric or string fields: `range_query(field, min, max)`
//! - Update specific field without replacing the full record: `update_field(key, field, value)`
//! - Text search on string fields: `search_contains(field, substring)`
//! - Filter records using a custom predicate: `filter(|val| ...)`
//! - Pagination for queries: `query_page(field, value, limit, offset)`
//! - Export query results to a JSON file: `export_query(field, value, path)`
//! - Export/import full database: `export_to_file(path)`, `import_from_file(path)`
//! - Compact database to reclaim space (like SQLite VACUUM): `compact()`
//! - Show all stored records
//!
//! ## Examples
//!
//! ### Open or Create a Database
//!
//! ```rust
//! use sqjson::{YourDb, DbError};
//! use serde_json::json;
//!
//! fn main() -> Result<(), DbError> {
//!     let mut db = YourDb::open("jsondb.db")?;
//!
//!     // Insert JSON records
//!     db.put("user:1", &json!({ "name": "Alice", "age": 30, "city": "NY" }))?;
//!     db.put("user:2", &json!({ "name": "Bob", "age": 25, "city": "LA" }))?;
//!
//!     // Flush to disk
//!     db.flush()?;
//!     Ok(())
//! }
//! ```
//!
//! ### Query by Field
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # fn run() -> Result<(), DbError> {
//! let db = YourDb::open("jsondb.db")?;
//!
//! let users_age_30 = db.query("age", 30)?;
//! println!("Users with age 30: {:?}", users_age_30);
//!
//! let users_city_ny = db.query("city", "NY")?;
//! println!("Users in NY: {:?}", users_city_ny);
//! # Ok(()) }
//! ```
//!
//! ### Range Query
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # use serde_json::json;
//! # fn run() -> Result<(), DbError> {
//! let db = YourDb::open("jsondb.db")?;
//! let age_range = db.range_query("age", json!(20), json!(30))?;
//! println!("Users age 20–30: {:?}", age_range);
//! # Ok(()) }
//! ```
//!
//! ### Update a Single Field
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # use serde_json::json;
//! # fn run() -> Result<(), DbError> {
//! let mut db = YourDb::open("jsondb.db")?;
//! db.update_field("user:2", "city", json!("SF"))?;
//! # Ok(()) }
//! ```
//!
//! ### Search by Substring
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # fn run() -> Result<(), DbError> {
//! let db = YourDb::open("jsondb.db")?;
//! let results = db.search_contains("name", "li")?;
//! println!("Users with 'li' in name: {:?}", results);
//! # Ok(()) }
//! ```
//!
//! ### Export / Import
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # fn run() -> Result<(), DbError> {
//! let mut db = YourDb::open("jsondb.db")?;
//! db.export_to_file("backup.json")?;
//! db.import_from_file("backup.json")?;
//! # Ok(()) }
//! ```
//!
//! ### Compact Database
//!
//! ```rust
//! # use sqjson::{YourDb, DbError};
//! # fn run() -> Result<(), DbError> {
//! let mut db = YourDb::open("jsondb.db")?;
//! db.compact()?; // Reclaim space after deletes
//! # Ok(()) }
//! ```
mod db;
mod pager;
mod page;
mod file;
mod error;
mod util;

pub use db::YourDb;
pub use error::DbError;