-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmulti-env.rs
52 lines (40 loc) · 1.2 KB
/
multi-env.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
43
44
45
46
47
48
49
50
51
52
use std::error::Error;
use byteorder::BE;
use heed::types::*;
use heed::{Database, EnvOpenOptions};
type BEU32 = U32<BE>;
fn main() -> Result<(), Box<dyn Error>> {
let env1_path = tempfile::tempdir()?;
let env2_path = tempfile::tempdir()?;
let env1 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env1_path)?
};
let env2 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env2_path)?
};
let mut wtxn1 = env1.write_txn()?;
let mut wtxn2 = env2.write_txn()?;
let db1: Database<Str, Bytes> = env1.create_database(&mut wtxn1, Some("hello"))?;
let db2: Database<BEU32, BEU32> = env2.create_database(&mut wtxn2, Some("hello"))?;
// clear db
db1.clear(&mut wtxn1)?;
wtxn1.commit()?;
// clear db
db2.clear(&mut wtxn2)?;
wtxn2.commit()?;
// -----
let mut wtxn1 = env1.write_txn()?;
db1.put(&mut wtxn1, "what", &[4, 5][..])?;
db1.get(&wtxn1, "what")?;
wtxn1.commit()?;
let rtxn2 = env2.read_txn()?;
let ret = db2.last(&rtxn2)?;
assert_eq!(ret, None);
Ok(())
}