surreal_sync_core/sink/connect.rs
1//! Traits for connecting a concrete Surreal sink (and its matching checkpoint store)
2//! from [`SurrealConfig`].
3
4use super::{SurrealConfig, SurrealSink};
5use crate::CheckpointStore;
6use async_trait::async_trait;
7
8/// Connect a single Surreal sink implementation from plain config.
9///
10/// In your app, pick one sink type, e.g. `run::<Surreal3Sink>(…)`.
11/// The stock CLI may still auto-detect and branch across both SDKs.
12#[async_trait]
13pub trait SinkConnect: SurrealSink + Sized {
14 /// Connect using endpoint / credentials / ns / db from [`SurrealConfig`].
15 async fn connect(config: &SurrealConfig) -> anyhow::Result<Self>;
16}
17
18/// Sink that can open a SurrealDB-table [`CheckpointStore`] for the same SDK major.
19///
20/// Embedders pick a sink crate (`surreal-sync-surreal` with `v2` / `v3`);
21/// that type carries the correct checkpoint backend. Origin `run` / `run_sync` APIs
22/// call this when `--checkpoints-surreal-table` is set — embedders never construct
23/// stores or clients by hand.
24///
25/// Filesystem checkpoints (`--checkpoint-dir`) are handled by the source crate, not this trait.
26pub trait SinkWithCheckpoints: SinkConnect {
27 /// Checkpoint store that matches this sink's SurrealDB SDK major.
28 type CheckpointStore: CheckpointStore;
29
30 /// Build a table-backed checkpoint store reusing this connected sink's client.
31 fn table_checkpoints(&self, table: String) -> Self::CheckpointStore;
32}