Skip to content

Commit bc17c80

Browse files
committed
feat: use synced database when sync API available
1 parent c6e4e09 commit bc17c80

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libsql/src/database/builder.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,28 @@ cfg_replication! {
342342
crate::util::ConnectorService::new(svc)
343343
};
344344

345+
let client = hyper::client::Client::builder()
346+
.build::<_, hyper::Body>(connector.clone());
347+
348+
let req = http::Request::get(format!("{url}/sync/0/0/0"))
349+
.header("Authorization", format!("Bearer {}", auth_token))
350+
.body(hyper::Body::empty())
351+
.unwrap();
352+
353+
let res = client
354+
.request(req)
355+
.await
356+
.map_err(|err| crate::Error::Sync(err.into()))?;
357+
358+
match res.status() {
359+
hyper::StatusCode::OK => return Builder::new_synced_database(path, url, auth_token)
360+
.remote_writes(true)
361+
.read_your_writes(read_your_writes)
362+
.build()
363+
.await,
364+
_ => {}
365+
}
366+
345367
let path = path.to_str().ok_or(crate::Error::InvalidUTF8Path)?.to_owned();
346368

347369
let db = if !skip_safety_assert {

0 commit comments

Comments
 (0)