Rust mock-store is a simple Rust in-memory mock-store for testing and prototyping (with modql implementation).
Do not use this in production code.
mock-store uses modql for filtering capability. It's also a great way to experiment with modql.
Example | Library Scope | Limitations
Example
See examples/readme.rs for the full working source.
// -- Store is Send + Sync (backed by Arc/Mutex).
let store = new;
// -- Insert the objects.
store.insert?;
store.insert?;
// -- List all tickets (no filter).
let all_tickets = store.?;
// [Ticket { id: 1, title: "Ticket AAA" }, Ticket { id: 1, title: "Ticket BBB" }]
println!;
// -- List with filter (using modql: https://github.com/jeremychone/rust-modql)
let filter: FilterGroup = vec!.into;
let double_a_tickets = store.?;
// [Ticket { id: 1, title: "Ticket AAA" }]
println!;
// -- Update with filter.
let filter: FilterGroup = vec!.into;
let count = store.?;
// 1
println!;
// -- List all tickets again.
let all_tickets = store.?;
// [Ticket { id: 1, title: "Ticket AAA" }, Ticket { id: 1, title: "TICKET BB - UPDATE" }]
println!;
// -- Delete is: store.delete::<Ticket>(filter)?;
Library Scope
- This is not intended for production use.
- Primarily for writing tests or proofs of concept without a real data store.
- Prioritizes ergonomics and convenience over performance.
Current Limitations
- Capability: For now, supports only one level down matches and numbers, booleans, strings.
- Performance: The store is per type, but the object store contains the serialized serde_json Value.
- Performance: Because objects are stored as Value, during an update, objects are deserialized and re-serialized.