#[derive(Debug, Clone)]
pub enum CheckpointStorage {
Disabled,
Filesystem { dir: String },
SurrealDB {
table_name: String,
namespace: String,
database: String,
},
}
#[derive(Debug, Clone)]
pub struct SyncConfig {
pub incremental: bool,
pub emit_checkpoints: bool,
pub checkpoint_storage: CheckpointStorage,
}
impl Default for SyncConfig {
fn default() -> Self {
Self {
incremental: false,
emit_checkpoints: true,
checkpoint_storage: CheckpointStorage::Filesystem {
dir: ".surreal-sync-checkpoints".to_string(),
},
}
}
}
impl SyncConfig {
pub fn new() -> Self {
Self::default()
}
pub fn full_sync_with_checkpoints(checkpoint_dir: String) -> Self {
Self {
incremental: false,
emit_checkpoints: true,
checkpoint_storage: CheckpointStorage::Filesystem {
dir: checkpoint_dir,
},
}
}
pub fn full_sync_with_surrealdb_checkpoints(
table_name: String,
namespace: String,
database: String,
) -> Self {
Self {
incremental: false,
emit_checkpoints: true,
checkpoint_storage: CheckpointStorage::SurrealDB {
table_name,
namespace,
database,
},
}
}
pub fn incremental() -> Self {
Self {
incremental: true,
emit_checkpoints: false,
checkpoint_storage: CheckpointStorage::Disabled,
}
}
pub fn should_emit_checkpoints(&self) -> bool {
self.emit_checkpoints && !matches!(self.checkpoint_storage, CheckpointStorage::Disabled)
}
}