|
2 | 2 | //!
|
3 | 3 | //! - [Decode Values on Demand](#decode-values-on-demand)
|
4 | 4 | //! - [Listing and Opening the Named Databases](#listing-and-opening-the-named-databases)
|
| 5 | +//! - [Moving entries from one database to another](#moving-entries-from-one-database-to-another) |
5 | 6 | //! - [Create Custom and Prefix Codecs](#create-custom-and-prefix-codecs)
|
6 | 7 | //! - [Change the Environment Size Dynamically](#change-the-environment-size-dynamically)
|
7 | 8 | //! - [Advanced Multithreaded Access of Entries](#advanced-multithreaded-access-of-entries)
|
|
129 | 130 | //! }
|
130 | 131 | //! ```
|
131 | 132 | //!
|
| 133 | +//! # Moving entries from one database to another |
| 134 | +//! |
| 135 | +//! TBD |
| 136 | +//! |
| 137 | +//! ```rust,compile_fail |
| 138 | +//! # use std::error::Error; |
| 139 | +//! # use heed::types::*; |
| 140 | +//! # use heed::{Database, EnvOpenOptions}; |
| 141 | +//! # fn main() -> Result<(), Box<dyn Error + Send + Sync>> { |
| 142 | +//! # let path = tempfile::tempdir()?; |
| 143 | +//! # let env = unsafe { |
| 144 | +//! # EnvOpenOptions::new() |
| 145 | +//! # .map_size(1024 * 1024 * 100) // 100 MiB |
| 146 | +//! # .open(&path)? |
| 147 | +//! # }; |
| 148 | +//! let mut wtxn = env.write_txn()?; |
| 149 | +//! # let database1: Database<Str, Str> = env.create_database(&mut wtxn, Some("database1"))?; |
| 150 | +//! # let database2: Database<Str, Str> = env.create_database(&mut wtxn, Some("database2"))?; |
| 151 | +//! # for i in 0..10 { |
| 152 | +//! # let key = format!("key{}", i); |
| 153 | +//! # let value = format!("value{}", i); |
| 154 | +//! # database1.put(&mut wtxn, &key, &value)?; |
| 155 | +//! # } |
| 156 | +//! for result in database1.iter(&wtxn)? { |
| 157 | +//! let (k, v) = result?; |
| 158 | +//! // compilation error: cannot use &mut and & of RwTxn simultaneously |
| 159 | +//! database2.put(&mut wtxn, k, v)?; |
| 160 | +//! } |
| 161 | +//! # wtxn.commit()?; |
| 162 | +//! # Ok(()) |
| 163 | +//! # } |
| 164 | +//! ``` |
| 165 | +//! |
| 166 | +//! TBD we use an iter_mut + as_wtxn and owned strings. Explain why this is necessary. |
| 167 | +//! |
| 168 | +//! ``` |
| 169 | +//! # use std::error::Error; |
| 170 | +//! # use heed::types::*; |
| 171 | +//! # use heed::{Database, EnvOpenOptions}; |
| 172 | +//! # fn main() -> Result<(), Box<dyn Error + Send + Sync>> { |
| 173 | +//! # let path = tempfile::tempdir()?; |
| 174 | +//! # let env = unsafe { |
| 175 | +//! # EnvOpenOptions::new() |
| 176 | +//! # .max_dbs(10) |
| 177 | +//! # .map_size(1024 * 1024 * 100) // 100 MiB |
| 178 | +//! # .open(&path)? |
| 179 | +//! # }; |
| 180 | +//! let mut wtxn = env.write_txn()?; |
| 181 | +//! # let database1: Database<Str, Str> = env.create_database(&mut wtxn, Some("database1"))?; |
| 182 | +//! # let database2: Database<Str, Str> = env.create_database(&mut wtxn, Some("database2"))?; |
| 183 | +//! # for i in 0..10 { |
| 184 | +//! # let key = format!("key{}", i); |
| 185 | +//! # let value = format!("value{}", i); |
| 186 | +//! # database1.put(&mut wtxn, &key, &value)?; |
| 187 | +//! # } |
| 188 | +//! let mut iter = database1.iter_mut(&mut wtxn)?; |
| 189 | +//! while let Some((k, v)) = iter.next().transpose()? { |
| 190 | +//! let ck = k.to_owned(); |
| 191 | +//! let cv = v.to_owned(); |
| 192 | +//! database2.put(iter.as_wtxn(), &ck, &cv)?; |
| 193 | +//! } |
| 194 | +//! # drop(iter); |
| 195 | +//! # wtxn.commit()?; |
| 196 | +//! # Ok(()) |
| 197 | +//! # } |
| 198 | +//! ``` |
| 199 | +//! |
132 | 200 | //! # Create Custom and Prefix Codecs
|
133 | 201 | //!
|
134 | 202 | //! With heed you can store any kind of data and serialize it the way you want.
|
|
0 commit comments