Crates.io | synclite |
lib.rs | synclite |
version | 0.2.2 |
source | src |
created_at | 2023-06-17 10:42:24.273087 |
updated_at | 2023-09-30 14:42:47.735338 |
description | SQLite replication |
homepage | |
repository | https://github.com/fmeringdal/synclite |
max_upload_size | |
id | 892824 |
size | 105,907 |
Synclite is a SQLite streaming replication Rust library inspired by Litestream.
CAUTION This library is currently in an experimental stage and contains known bugs, making it unsuitable for production use at this time.
Synclite is a library that is meant to be used within your application.
Start by setting up minio to store the replicated data
docker run -p 9000:9000 -p 9001:9001 minio/minio:latest server /data --console-address ":9001"
This is how you would replicate a SQLite DB at path tmp.db
:
std::env::set_var("AWS_ACCESS_KEY_ID", "minioadmin");
std::env::set_var("AWS_SECRET_ACCESS_KEY", "minioadmin");
let s3_replica_config = synclite::replica::s3::Config {
bucket: "mybkt".to_string(),
endpoint: Some("http://localhost:9000".to_string()),
region: "eu-west-1".to_string(),
prefix: "tmp.db".to_string(),
};
let config = synclite::config::ReplicateConfig {
db_path: "tmp.db".to_string(),
replica: synclite::replica::Config::S3(s3_replica_config.clone()),
// This should be set if you use SQLCipher
encryption_key: None,
};
let (stop_tx, stop_rx) = tokio::sync::broadcast::channel(1);
// Start replication in a background task
tokio::spawn({
let config = config.clone();
async move {
synclite::replicate(config.clone(), stop_rx).await.unwrap();
}
});
This is how you would restore your SQLite DB from MinIO to the local path restored.db
:
std::env::set_var("AWS_ACCESS_KEY_ID", "minioadmin");
std::env::set_var("AWS_SECRET_ACCESS_KEY", "minioadmin");
let s3_replica_config = synclite::replica::s3::Config {
bucket: "mybkt".to_string(),
endpoint: Some("http://localhost:9000".to_string()),
region: "eu-west-1".to_string(),
prefix: "tmp.db".to_string(),
};
let restore_config = synclite::config::RestoreConfig {
db_path: "restored.db".to_string(),
replica: synclite::replica::Config::S3(s3_replica_config.clone()),
if_not_exists: true,
encryption_key: None,
};
synclite::restore(restore_config.clone()).await.unwrap();