FOSK
fosk is a lightweight embedded SQL engine for Rust applications.
It allows you to define in-memory collections, seed them with JSON objects, and query using a SQL-like syntax.
โจ Features
- In-memory database with collections (tables)
- Configurable ID strategies: integer, UUID, or none
- Simple JSON storage (serde_json::Value)
- SQL parser with support for:
- SELECT, WHERE, GROUP BY, HAVING
- JOIN (inner, left, right, full)
- ORDER BY, LIMIT, OFFSET
- Parameterized queries (? placeholders, including arrays)
- Test-friendly: create databases on the fly and seed them
Installation
In your Cargo.toml:
[]
= "0.1.1"
= "1"
Quick example
use ;
use json;
๐ Main Types & API
Db
Represents a database.
- new_db_with_config(config: Config) -> Db
- create_collection(name: &str) -> CollectionHandle
- query(sql: &str) -> Result<Vec, AnalyzerError>
- query_with_args(sql: &str, args: Value) -> Result<Vec, AnalyzerError>
Config
Defines collection behavior.
- Config::int("id") โ auto-increment integer IDs
- Config::uuid("id") โ UUID v4 IDs
- Config::none("id") โ no automatic ID field
CollectionHandle
- add(item: Value) -> Option
- get_all() -> Vec
- get(id: &str) -> Option
- update(id: &str, item: Value) -> Option
- delete(id: &str) -> Option
extras
- get_paginated(, offset: usize, limit: usize) -> Vec
- exists(id: &str) -> bool
- count() -> usize
- add_batch(items: Value) -> Vec
- update_partial(id: &str, partial_item: Value) -> Option
- clear() -> usize
Load from existing data
;
let db = new;
let people = db.create_collection;
people.load_from_file;
= new;
let people = db.create_collection;
people.load_from_json;
๐งช Testing & Seeding
Example test seed (see fixtures::seed_db):
โ ๏ธ Notes
- Collection names are case-sensitive: "People" is different from "people".
- Projections normally output unqualified field names (id, name), unless duplicates exist. In case of conflicts, names are disambiguated with their collection prefix (id, o.id).
๐ License
Licensed under the MIT License. See LICENSE for details.