Skip to main content

ecat_data/
document.rs

1// Copyright (c) 2026 erik <erik@erik.xyz> — https://erik.xyz
2use async_trait::async_trait;
3use ecat_errors::Error;
4
5/// Document-store client abstraction (e.g. MongoDB).
6#[async_trait]
7pub trait DocumentClient: Send + Sync {
8    /// Insert a document into `collection`, returning its id.
9    async fn insert(&self, collection: &str, doc: &serde_json::Value) -> Result<String, Error>;
10
11    /// Find documents matching `filter` (backend-specific JSON query syntax).
12    async fn find(
13        &self,
14        collection: &str,
15        filter: &serde_json::Value,
16    ) -> Result<Vec<serde_json::Value>, Error>;
17
18    /// Update documents matching `filter`; returns the number of modified documents.
19    async fn update(
20        &self,
21        collection: &str,
22        filter: &serde_json::Value,
23        update: &serde_json::Value,
24    ) -> Result<u64, Error>;
25
26    /// Delete documents matching `filter`; returns the number of deleted documents.
27    async fn delete(&self, collection: &str, filter: &serde_json::Value) -> Result<u64, Error>;
28}