Skip to main content

ubiquisync_sql/
store.rs

1//! SQL-backed [`Store`](ubiquisync_core::store::Store) adding ad-hoc read queries.
2
3use ubiquisync_core::event::RoutableEvent;
4
5use crate::{
6    db::{DbError, DbRow, DbValue},
7    dialect::SqlDialect,
8    processor::{BoxError, ProcessorError},
9};
10
11/// A [`Store`](ubiquisync_core::store::Store) backed by SQL, adding ad-hoc reads.
12///
13/// The inherited [`Store`](ubiquisync_core::store::Store) surface (`exec`) always
14/// errors as the SQL engine's [`ProcessorError<BoxError>`], so it's pinned in the
15/// supertrait bound rather than left as a parameter. [`query`](SqlStore::query)
16/// reports its own [`DbError`] instead.
17#[async_trait::async_trait]
18pub trait SqlStore<Op, Event: RoutableEvent>:
19    ubiquisync_core::store::Store<Op, ProcessorError<BoxError>, Event>
20{
21    /// Run a read-only query against the backend.
22    async fn query(&self, sql: &str, params: &[DbValue]) -> Result<Vec<DbRow>, DbError>;
23
24    /// The backend's SQL dialect — lets a caller build dialect-correct SQL
25    /// (placeholder style, quoting) to hand back to [`query`](SqlStore::query).
26    fn dialect(&self) -> SqlDialect;
27}