cli: Open tracking DB in read-only mode

This commit is contained in:
Alexis Sellier 2023-03-15 12:12:16 +01:00
parent 05d7090326
commit bd436d4369
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View File

@ -153,7 +153,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
control::stop(node)?;
}
Operation::Tracking { mode } => {
let store = radicle::node::tracking::store::Config::open(
let store = radicle::node::tracking::store::Config::reader(
profile.home.node().join(TRACKING_DB_FILE),
)?;
tracking::run(&store, mode)?

View File

@ -42,6 +42,15 @@ impl Config {
Ok(Self { db })
}
/// Same as [`Self::open`], but in read-only mode. This is useful to have multiple
/// open databases, as no locking is required.
pub fn reader<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let db = sql::Connection::open_with_flags(path, sqlite::OpenFlags::new().set_read_only())?;
db.execute(Self::SCHEMA)?;
Ok(Self { db })
}
/// Create a new in-memory address book.
pub fn memory() -> Result<Self, Error> {
let db = sql::Connection::open(":memory:")?;