Rust

mirror

Module

[Mirror]: a database whose writes are copied to a second one.

A mirror reads from and writes to its source; every write that succeeds there is repeated on the destination (when it has one), through the Filters, and a failure on the destination is only reported to the Mirror::on_error callbacks: the source stays the truth. Document writes reach the destination only for collections the source's upgrades collection marks upgraded, which a collection created through the mirror is.

Rust
use std::sync::Arc;

use utopia_database::Document;
use utopia_database::mirror::Mirror;

let mirror = Mirror::new(source, Some(destination), Vec::new());
mirror.on_error(Arc::new(|action: &str, error: &utopia_database::Error| {
    eprintln!("{action}: {}", error.message());
    Ok(())
}));
mirror.create_collection("people", Vec::new(), Vec::new(), None, true).await?;
mirror.create_document("people", Document::default()).await?;
Compiles in CI; needs a running service to execute.

Contents

use utopia_database::mirror::Mirror;
Rust
pub struct Mirror

A database whose writes are copied to a destination. See the module docs.

Rust
pub type ErrorCallback = Arc<dyn Fn(&str, &Error) -> Result<()> + Send + Sync>

A callback Mirror::on_error registers: the action (createDocument, ...) and the error the destination raised. An error it returns leaves the mirror's call.