redb_32bit/
lib.rs

1#![allow(clippy::drop_non_drop)]
2#![deny(
3    clippy::cast_possible_truncation,
4    clippy::cast_possible_wrap,
5    clippy::cast_precision_loss,
6    clippy::cast_sign_loss,
7    clippy::disallowed_methods
8)]
9// TODO remove this once wasi no longer requires nightly
10#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
11
12//! # redb
13//!
14//! A simple, portable, high-performance, ACID, embedded key-value store.
15//!
16//! redb is written in pure Rust and is loosely inspired by [lmdb][lmdb]. Data is stored in a collection
17//! of copy-on-write B-trees. For more details, see the [design doc][design].
18//!
19//! # Features
20//!
21//! - Zero-copy, thread-safe, `BTreeMap` based API
22//! - Fully ACID-compliant transactions
23//! - MVCC support for concurrent readers & writer, without blocking
24//! - Crash-safe by default
25//! - Savepoints and rollbacks
26//!
27//! # Example
28//!
29//! ```
30//! use redb::{Database, Error, ReadableTable, TableDefinition};
31//!
32//! const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");
33//!
34//! #[cfg(not(target_os = "wasi"))]
35//! fn main() -> Result<(), Error> {
36//!     let file = tempfile::NamedTempFile::new().unwrap();
37//!     let db = Database::create(file.path())?;
38//!     let write_txn = db.begin_write()?;
39//!     {
40//!         let mut table = write_txn.open_table(TABLE)?;
41//!         table.insert("my_key", &123)?;
42//!     }
43//!     write_txn.commit()?;
44//!
45//!     let read_txn = db.begin_read()?;
46//!     let table = read_txn.open_table(TABLE)?;
47//!     assert_eq!(table.get("my_key")?.unwrap().value(), 123);
48//!
49//!     Ok(())
50//! }
51//! ```
52//!
53//! [lmdb]: https://www.lmdb.tech/doc/
54//! [design]: https://github.com/cberner/redb/blob/master/docs/design.md
55
56pub use db::{
57    Builder, Database, MultimapTableDefinition, MultimapTableHandle, RepairSession, StorageBackend,
58    TableDefinition, TableHandle, UntypedMultimapTableHandle, UntypedTableHandle,
59};
60pub use error::{
61    CommitError, CompactionError, DatabaseError, Error, SavepointError, StorageError, TableError,
62    TransactionError,
63};
64pub use multimap_table::{
65    MultimapRange, MultimapTable, MultimapValue, ReadOnlyMultimapTable,
66    ReadOnlyUntypedMultimapTable, ReadableMultimapTable,
67};
68pub use table::{
69    Drain, DrainFilter, Range, ReadOnlyTable, ReadOnlyUntypedTable, ReadableTable, Table,
70    TableStats,
71};
72pub use transactions::{DatabaseStats, Durability, ReadTransaction, WriteTransaction};
73pub use tree_store::{AccessGuard, AccessGuardMut, Savepoint};
74pub use types::{MutInPlaceValue, RedbKey, RedbValue, TypeName};
75
76type Result<T = (), E = StorageError> = std::result::Result<T, E>;
77
78#[cfg(feature = "python")]
79pub use crate::python::redb;
80
81pub mod backends;
82mod complex_types;
83mod db;
84mod error;
85mod multimap_table;
86#[cfg(feature = "python")]
87mod python;
88mod sealed;
89mod table;
90mod transaction_tracker;
91mod transactions;
92mod tree_store;
93mod tuple_types;
94mod types;
95
96#[cfg(test)]
97fn create_tempfile() -> tempfile::NamedTempFile {
98    if cfg!(target_os = "wasi") {
99        tempfile::NamedTempFile::new_in("/").unwrap()
100    } else {
101        tempfile::NamedTempFile::new().unwrap()
102    }
103}