pub trait ObjectStore {
// Required methods
fn put_object(&mut self, object: MemoryObject) -> ThingdResult<MemoryObject>;
fn get_object(
&self,
collection: &str,
id: &str,
) -> ThingdResult<Option<MemoryObject>>;
fn list_objects(
&self,
collections: Option<&[String]>,
options: &ListObjectsOptions,
) -> ThingdResult<Vec<MemoryObject>>;
fn delete_object(
&mut self,
collection: &str,
id: &str,
) -> ThingdResult<bool>;
fn count_objects(&self) -> ThingdResult<u64>;
fn list_collections(&self) -> ThingdResult<Vec<String>>;
// Provided method
fn put_objects_batch(
&mut self,
objects: Vec<MemoryObject>,
) -> ThingdResult<Vec<MemoryObject>> { ... }
}Expand description
Object storage operations.
§Examples
use thingd_core::{MemoryEngine, ObjectStore, MemoryObject};
let mut store = MemoryEngine::new();
let obj = MemoryObject::new("users", "alice", r#"{"name":"Alice"}"#);
store.put_object(obj).unwrap();
let user = store.get_object("users", "alice").unwrap();
assert!(user.is_some());
assert_eq!(store.count_objects().unwrap(), 1);Required Methods§
Sourcefn put_object(&mut self, object: MemoryObject) -> ThingdResult<MemoryObject>
fn put_object(&mut self, object: MemoryObject) -> ThingdResult<MemoryObject>
Insert or replace an object.
§Errors
Returns an error when the backing store cannot persist the object.
Sourcefn get_object(
&self,
collection: &str,
id: &str,
) -> ThingdResult<Option<MemoryObject>>
fn get_object( &self, collection: &str, id: &str, ) -> ThingdResult<Option<MemoryObject>>
Read an object by collection and id.
§Errors
Returns an error when the backing store cannot read the object.
Sourcefn list_objects(
&self,
collections: Option<&[String]>,
options: &ListObjectsOptions,
) -> ThingdResult<Vec<MemoryObject>>
fn list_objects( &self, collections: Option<&[String]>, options: &ListObjectsOptions, ) -> ThingdResult<Vec<MemoryObject>>
List objects in one or more collections, with optional filtering, limit, and offset.
Pass an empty ListObjectsOptions to return all objects across all collections.
§Errors
Returns an error when the backing store cannot list objects.
Sourcefn delete_object(&mut self, collection: &str, id: &str) -> ThingdResult<bool>
fn delete_object(&mut self, collection: &str, id: &str) -> ThingdResult<bool>
Delete an object by collection and id.
§Errors
Returns an error when the backing store cannot delete the object.
Sourcefn count_objects(&self) -> ThingdResult<u64>
fn count_objects(&self) -> ThingdResult<u64>
Count total objects across all collections.
§Errors
Returns an error when the backing store cannot count objects.
Sourcefn list_collections(&self) -> ThingdResult<Vec<String>>
fn list_collections(&self) -> ThingdResult<Vec<String>>
List all unique collection names.
§Errors
Returns an error when the backing store cannot list collections.
Provided Methods§
Sourcefn put_objects_batch(
&mut self,
objects: Vec<MemoryObject>,
) -> ThingdResult<Vec<MemoryObject>>
fn put_objects_batch( &mut self, objects: Vec<MemoryObject>, ) -> ThingdResult<Vec<MemoryObject>>
Insert or replace multiple objects in a single transaction.
This is significantly faster than calling put_object in a loop
because it avoids per-object transaction overhead.
§Errors
Returns an error when the backing store cannot persist any object.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".