Skip to main content

Crate bothy

Crate bothy 

Source
Expand description

§Bothy

Bothy is a local-first sync engine for applications that have no server of their own. Each device keeps its data in a local SQLite database, and devices exchange immutable, append-only files through the user’s own cloud storage (Google Drive first).

Status: early development. The local store, the merge rules, the file formats and the sync engine work against a local or shared folder (remote::FolderRemote). The Google Drive backend and the CLI are in progress at https://github.com/bothy-sync/bothy.

use std::sync::Arc;
use bothy::{Config, Database, remote::FolderRemote};
use serde_json::json;

let remote = Arc::new(FolderRemote::new(shared)?);

// Device A creates the database and writes a note.
let a = Database::open(Config::new(local_a, "com.example.notes"), remote.clone()).await?;
let db_id = a.init().await?;
a.collection("notes")?.put("n1", json!({"title": "Hello"})).await?;
a.sync().await?;

// Device B joins and receives it.
let b = Database::open(Config::new(local_b, "com.example.notes"), remote).await?;
b.join(db_id).await?;
let note = b.collection("notes")?.get("n1").await?.unwrap();
assert_eq!(note.to_json(), json!({"title": "Hello"}));

Re-exports§

pub use model::CollectionName;
pub use model::DbId;
pub use model::DeviceId;
pub use model::DocId;
pub use model::FieldName;
pub use model::Op;
pub use model::OpKind;
pub use model::Stamp;
pub use model::Value;

Modules§

auth
Access tokens for remote backends. OAuth flows live outside the core (CLI, app, binding); the core only asks for a token and reports a rejected one.
blocking
Synchronous API for callers without an async runtime (CLI, Python, C).
codec
Wire encodings and remote file formats.
crypto
Client-side encryption (feature crypto): Argon2id key derivation and XChaCha20-Poly1305.
merge
Field-level last-writer-wins merge with delete stamps. Pure: no I/O.
model
Data model: values, identifiers, operations.
p2p
Direct channel between online devices (WebRTC data channel, str0m on its aws-lc-rs crypto backend).
remote
Remote storage backends. Every file is immutable once written; there is no overwrite.
store
Local SQLite store: merge state, read view and outbox, kept consistent in one transaction.

Structs§

AutoSync
Timing of background sync.
ChangeEvent
A document’s visible content changed.
Collection
A collection of documents in a Database.
CompactReport
Files a compaction run deleted (or would delete, for a dry run).
Config
Settings for Database::open.
Database
A local-first database that syncs through a RemoteStore.
Error
A Bothy error: a ErrorKind, a message and an optional underlying cause.
Hlc
A hybrid logical clock timestamp.
HlcClock
Produces monotonically increasing Hlc timestamps for one device.
ListOptions
Options for Collection::list.
ParseHlcError
Error returned when parsing an Hlc from its hex form fails.
SnapshotPolicy
When to snapshot and how long to keep covered files.
SyncHandle
Controls a background sync task. Dropping it stops the task.
SyncReport
What one Database::sync call did.
SystemClock
The operating system clock.

Enums§

ErrorKind
Broad error category. Callers branch on this; the message is for humans.
Origin
Where a change came from.
SyncStatus
Outcome of the latest background sync.

Constants§

DEFAULT_MAX_DRIFT_MS
Default limit on how far a remote timestamp may pull the local clock ahead of the wall clock.
FORMAT_VERSION
Version of the on-remote file format written by this crate (bothy_format in manifest.json). Draft: the format is not frozen until SPEC.md v1.

Traits§

Clock
Wall-clock source in milliseconds since the Unix epoch. Tests inject a fake one.
IntoDocument
Types that can be written as a whole document.

Type Aliases§

Result
Result type used throughout Bothy.