Skip to main content

surreal_sync_core/sink/
config.rs

1//! SurrealDB connection and write settings (plain fields, no CLI parsing).
2
3use crate::ZeroTemporalPolicy;
4
5/// Plain-field SurrealDB connection and write options (no clap).
6///
7/// Use this from embedders and [`SinkConnect`](super::SinkConnect) helpers.
8/// The stock CLI continues to parse argv into clap-derived structs and maps
9/// them into this type (or sink-crate connect helpers) at the boundary.
10#[derive(Debug, Clone)]
11pub struct SurrealConfig {
12    /// SurrealDB endpoint URL (`http://…` or `ws://…`).
13    pub endpoint: String,
14    /// Username for SurrealDB sign-in.
15    pub username: String,
16    /// Password for SurrealDB sign-in.
17    pub password: String,
18    /// Target namespace.
19    pub namespace: String,
20    /// Target database.
21    pub database: String,
22    /// How zero temporal values are written.
23    pub zero_temporal: ZeroTemporalPolicy,
24    /// Batch size hint for full-sync writers (sources that honor it).
25    pub batch_size: usize,
26    /// When true, sources should not write to the sink.
27    pub dry_run: bool,
28}
29
30impl Default for SurrealConfig {
31    fn default() -> Self {
32        Self {
33            endpoint: "http://localhost:8000".to_string(),
34            username: "root".to_string(),
35            password: "root".to_string(),
36            namespace: "test".to_string(),
37            database: "test".to_string(),
38            zero_temporal: ZeroTemporalPolicy::default(),
39            batch_size: 1000,
40            dry_run: false,
41        }
42    }
43}
44
45impl SurrealConfig {
46    /// Create a config with endpoint / credentials / ns / db.
47    pub fn new(
48        endpoint: impl Into<String>,
49        username: impl Into<String>,
50        password: impl Into<String>,
51        namespace: impl Into<String>,
52        database: impl Into<String>,
53    ) -> Self {
54        Self {
55            endpoint: endpoint.into(),
56            username: username.into(),
57            password: password.into(),
58            namespace: namespace.into(),
59            database: database.into(),
60            ..Self::default()
61        }
62    }
63}