refactor: dump database to json
This commit is contained in:
12
sdgb-cli/src/cache/mod.rs
vendored
12
sdgb-cli/src/cache/mod.rs
vendored
@@ -1,6 +1,6 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use redb::{Table, TableDefinition, WriteTransaction};
|
||||
use redb::{ReadTransaction, Table, TableDefinition, WriteTransaction};
|
||||
|
||||
static DATABASE: LazyLock<redb::Database> = LazyLock::new(|| {
|
||||
redb::Database::builder()
|
||||
@@ -17,6 +17,16 @@ pub fn open_table(write: &WriteTransaction) -> Result<Table<'_, u32, Vec<u8>>, r
|
||||
Ok(write.open_table(DIFINITION)?)
|
||||
}
|
||||
|
||||
pub fn read_txn() -> Result<ReadTransaction, redb::Error> {
|
||||
Ok(DATABASE.begin_read()?)
|
||||
}
|
||||
|
||||
pub fn open_table_read(
|
||||
read: &ReadTransaction,
|
||||
) -> Result<redb::ReadOnlyTable<u32, Vec<u8>>, redb::Error> {
|
||||
Ok(read.open_table(DIFINITION)?)
|
||||
}
|
||||
|
||||
pub fn init_db() -> Result<(), redb::Error> {
|
||||
let write_txn = DATABASE.begin_write()?;
|
||||
write_txn.open_table(DIFINITION)?;
|
||||
|
||||
Reference in New Issue
Block a user