ckb_db/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! # The DB Library
//!
//! This Library contains the `KeyValueDB` traits
//! which provides key-value store interface

use ckb_error::{Error, InternalErrorKind};
use std::{fmt, result};

pub mod db;
pub mod db_with_ttl;
pub mod iter;
pub mod read_only_db;
pub mod snapshot;
pub mod transaction;
pub mod write_batch;

#[cfg(test)]
mod tests;

pub use crate::db::RocksDB;
pub use crate::db_with_ttl::DBWithTTL;
pub use crate::iter::DBIterator;
pub use crate::read_only_db::ReadOnlyDB;
pub use crate::snapshot::RocksDBSnapshot;
pub use crate::transaction::{RocksDBTransaction, RocksDBTransactionSnapshot};
pub use crate::write_batch::RocksDBWriteBatch;
pub use rocksdb::{
    self as internal, DBPinnableSlice, DBVector, Direction, Error as DBError, IteratorMode,
    ReadOptions, WriteBatch,
};

/// The type returned by database methods.
pub type Result<T> = result::Result<T, Error>;

fn internal_error<S: fmt::Display>(reason: S) -> Error {
    let message = reason.to_string();
    if message.starts_with("Corruption:") {
        InternalErrorKind::Database.other(message).into()
    } else {
        InternalErrorKind::DataCorrupted.other(message).into()
    }
}