bindings/rust/rust-driver-sync.mdx
Turso - is the SQLite compatible database written in Rust. One of the important features of the Turso - is native ability to sync database with the Cloud in both directions (push local changes and pull remote changes).
Your task is to generate EXTRA functionality on top of the existing Rust driver which will extend regular embedded database with sync capability. Do not modify existing driver - its already implemented in the lib.rs Your task is to write extra code which will use abstractions from lib.rs and build sync support in the Rust on top of it in the lib.rs file.
General rules for driver implementation you MUST follow and never go against these rules:
/// A builder for `Database`.
pub struct Builder {
path: String,
remote_url: String,
auth_token: Option<String>,
client_name: Option<String>,
long_poll_timeout: Option<Duration>,
bootstrap_if_empty: bool,
partial_sync_config_experimental: Option<PartialSyncOpts>,
}
pub struct Database { ... }
impl Database {
pub async fn push(&self) -> crate::Result<()> { ... }
pub async fn pull(&self) -> crate::Result<bool> { ... }
pub async fn checkpoint(&self) -> crate::Result<()> { ... }
pub async fn stats(&self) -> crate::Result<DatabaseSyncStats> { ... }
pub async fn connect(&self) -> crate::Result<Connection> { ... }
}
impl Builder {
pub fn new_remote(path: &str, remote_url: &str) -> Self { ... }
/// ... more methods to configure builder with extra parameters ...
/// Build the synced database.
pub async fn build(self) -> crate::Result<Database> { ... }
}
TursoDatabaseAsyncOperationstep_io_callbacks in the IO thread after making some progress with IO (pushing more data, finishing request, etc)push_buffer methodturso_sync_database_create() method for creation of the synced database for now - DO NOT use init + open pairRequestBuilder is typed by the body type and this can cause conflict if you are using Full and Empty as bodyClient<HttpsConnector<HttpConnector>, Full<Bytes>> for hyper client
HttpConnector from hyper_util::client::legacy::connect::HttpConnectorturso-sync-rust as client_name if not set by userCurrent dreiver implementation consist of following main components:
<File path="./src/lib.rs" /> <File path="./src/connection.rs" />Your implementation must use sdk-kit for embedded db and sync extension Look at the rust API of the kit here:
<File path="../../sdk-kit/src/rsapi.rs" /> <File path="../../sync/sdk-kit/src/rsapi.rs" />Sync engine provide simple "step"-based API and you MUST integrate it to the Rust driver async: <File path="../../sync/sdk-kit/src/turso_async_operation.rs" /> <File path="../../sync/sdk-kit/src/sync_engine_io.rs" />
Be careful with TursoDatabaseAsyncOperation ownership as it is wrapped in unique Box container. You must use it from single place.
Use following example to get up-to date understanding of Hyper API:
<Link url="https://raw.githubusercontent.com/hyperium/hyper/refs/heads/master/examples/client.rs" />For HTTPS project already installed hyper_tls dep. You can inspect example here: