cli: Open tracking DB in read-only mode
This commit is contained in:
parent
05d7090326
commit
bd436d4369
|
|
@ -153,7 +153,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
control::stop(node)?;
|
control::stop(node)?;
|
||||||
}
|
}
|
||||||
Operation::Tracking { mode } => {
|
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),
|
profile.home.node().join(TRACKING_DB_FILE),
|
||||||
)?;
|
)?;
|
||||||
tracking::run(&store, mode)?
|
tracking::run(&store, mode)?
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,15 @@ impl Config {
|
||||||
Ok(Self { db })
|
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.
|
/// Create a new in-memory address book.
|
||||||
pub fn memory() -> Result<Self, Error> {
|
pub fn memory() -> Result<Self, Error> {
|
||||||
let db = sql::Connection::open(":memory:")?;
|
let db = sql::Connection::open(":memory:")?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue