Skip to main content

Crate fosk

Crate fosk 

Source
Expand description

In-memory SQL-like query engine and lightweight data store.

fosk lets tests and prototypes create JSON-backed collections in memory, then query them with a small SQL-like language. Most users start with Db, configure id behavior with DbConfig and IdType, and work with collection handles returned by Db::create or Db::get.

§Example

use fosk::{Db, DbConfig};
use serde_json::json;

let db = Db::new_with_config(DbConfig::int("id"));
let people = db.create("people");

let _inserted = people
    .add(json!({ "name": "Ada", "age": 37 }))
    .map_err(|error| error.to_string())?;

let rows = db
    .query("SELECT id, name FROM people WHERE age > 30")
    .map_err(|error| format!("{error:?}"))?;

assert_eq!(rows.len(), 1);

Re-exports§

pub use database::AddBatchError;
pub use database::AddError;
pub use database::CollectionReadError;
pub use database::CollectionWriteError;
pub use database::Db;
pub use database::DbCollection;
pub use database::DbConfig;
pub use database::FieldInfo;
pub use database::IdType;
pub use database::JsonPrimitive;
pub use database::LoadCollectionError;
pub use database::ReferenceColumn;
pub use database::SchemaDict;
pub use database::SchemaWithRefs;
pub use database::WriteCollectionError;

Modules§

database
Database handles, collection handles, configuration, and schema metadata. Database, collection, id, and schema APIs.