Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

libsql: attach databases from other namespaces as readonly #770

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sqld/src/connection/libsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ where
)?;
conn.conn
.pragma_update(None, "max_page_count", max_db_size)?;
let dbs_path = path
.as_ref()
.parent()
.unwrap_or_else(|| std::path::Path::new(".."))
.canonicalize()
.unwrap_or_else(|_| std::path::PathBuf::from(".."));
for entry in (std::fs::read_dir(&dbs_path)?).flatten() {
if let Some(namespace) = entry.file_name().to_str() {
let db_path = entry.path().join("data");
let query = format!(
"ATTACH DATABASE 'file:{}?mode=ro' AS \"{namespace}\"",
db_path.display()
);
if let Err(e) = conn.conn.execute(&query, ()) {
tracing::warn!("Failed to attach database {}: {}", db_path.display(), e);
} else {
tracing::debug!("Attached {} as {namespace}", db_path.display());
}
}
}
Ok(conn)
})
.await
Expand Down
Loading