Skip to main content

DataStore

Trait DataStore 

Source
pub trait DataStore: Send + Sync {
Show 14 methods // Required methods fn manifest(&self) -> &AppManifest; fn insert(&self, entity: &str, data: &Value) -> Result<String, DataError>; fn get_by_id( &self, entity: &str, id: &str, ) -> Result<Option<Value>, DataError>; fn list(&self, entity: &str) -> Result<Vec<Value>, DataError>; fn list_after( &self, entity: &str, after: Option<&str>, limit: usize, ) -> Result<Vec<Value>, DataError>; fn update( &self, entity: &str, id: &str, data: &Value, ) -> Result<bool, DataError>; fn delete(&self, entity: &str, id: &str) -> Result<bool, DataError>; fn lookup( &self, entity: &str, field: &str, value: &str, ) -> Result<Option<Value>, DataError>; fn link( &self, entity: &str, id: &str, relation: &str, target_id: &str, ) -> Result<bool, DataError>; fn unlink( &self, entity: &str, id: &str, relation: &str, ) -> Result<bool, DataError>; fn query_filtered( &self, entity: &str, filter: &Value, ) -> Result<Vec<Value>, DataError>; fn query_graph(&self, query: &Value) -> Result<Value, DataError>; fn transact(&self, ops: &[Value]) -> Result<(bool, Vec<Value>), DataError>; // Provided method fn aggregate( &self, _entity: &str, _spec: &Value, ) -> Result<Value, DataError> { ... }
}
Expand description

Platform-agnostic data store trait.

Implemented by Runtime (SQLite, self-hosted) and D1DataStore (Workers). All methods are synchronous to keep the trait Send + Sync and simple; Workers adapters can use block_on or similar bridging.

Required Methods§

Source

fn manifest(&self) -> &AppManifest

Source

fn insert(&self, entity: &str, data: &Value) -> Result<String, DataError>

Source

fn get_by_id(&self, entity: &str, id: &str) -> Result<Option<Value>, DataError>

Source

fn list(&self, entity: &str) -> Result<Vec<Value>, DataError>

Source

fn list_after( &self, entity: &str, after: Option<&str>, limit: usize, ) -> Result<Vec<Value>, DataError>

Source

fn update( &self, entity: &str, id: &str, data: &Value, ) -> Result<bool, DataError>

Source

fn delete(&self, entity: &str, id: &str) -> Result<bool, DataError>

Source

fn lookup( &self, entity: &str, field: &str, value: &str, ) -> Result<Option<Value>, DataError>

Source

fn query_filtered( &self, entity: &str, filter: &Value, ) -> Result<Vec<Value>, DataError>

Source

fn query_graph(&self, query: &Value) -> Result<Value, DataError>

Source

fn transact(&self, ops: &[Value]) -> Result<(bool, Vec<Value>), DataError>

Execute transactional operations. Each element is a JSON object with op (“insert”/“update”/“delete”), entity, and optionally id/data.

Returns per-operation results. The implementation decides whether to use real SQL transactions (Runtime) or sequential execution (D1).

Provided Methods§

Source

fn aggregate(&self, _entity: &str, _spec: &Value) -> Result<Value, DataError>

Run an aggregation query.

Spec shape (same vocabulary in the HTTP body):

{
  "count": "*",
  "sum": ["amount"],
  "avg": ["price"],
  "min": ["createdAt"],
  "max": ["createdAt"],
  "groupBy": ["status"],
  "where": { ...standard filter... }
}

Returns {rows: [{count, sum_amount, ...}]}. Default implementation returns NOT_SUPPORTED; Runtime overrides it.

Implementors§