Skip to content

Commit f2f0eda

Browse files
committed
Bootstrap the db on connect if required
1 parent aaa0ea0 commit f2f0eda

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

libsql/src/database.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,18 @@ impl Database {
675675
};
676676
use tokio::sync::Mutex;
677677

678+
let _ = tokio::task::block_in_place(move || {
679+
let rt = tokio::runtime::Builder::new_current_thread()
680+
.enable_all()
681+
.build()
682+
.unwrap();
683+
rt.block_on(async {
684+
// we will ignore if any errors occurred during the bootstrapping the db,
685+
// because the client could be offline when trying to connect.
686+
let _ = db.bootstrap_db().await;
687+
})
688+
});
689+
678690
let local = db.connect()?;
679691

680692
if *remote_writes {

libsql/src/local/database.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ impl Database {
473473
crate::sync::sync_offline(&mut sync_ctx, &conn).await
474474
}
475475

476+
#[cfg(feature = "sync")]
477+
/// Brings the .db file from server, if required.
478+
pub async fn bootstrap_db(&self) -> Result<()> {
479+
let mut sync_ctx = self.sync_ctx.as_ref().unwrap().lock().await;
480+
crate::sync::bootstrap_db(&mut sync_ctx).await
481+
}
482+
476483
pub(crate) fn path(&self) -> &str {
477484
&self.db_path
478485
}

0 commit comments

Comments
 (0)