Skip to content

Commit ee6eaad

Browse files
authored
open DB created by foreign language in raw mode by default (#128)
* open DB created by foreign language in raw mode by default * adds guide to open DB by foreign language in README and doc
1 parent ec2ba88 commit ee6eaad

File tree

10 files changed

+207
-127
lines changed

10 files changed

+207
-127
lines changed

Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "RocksDict"
3-
version = "0.3.24-beta.1"
3+
version = "0.3.24-beta.2"
44
edition = "2021"
55
description = "Rocksdb Python Binding"
66

@@ -10,6 +10,11 @@ description = "Rocksdb Python Binding"
1010
name = "rocksdict"
1111
crate-type = ["cdylib"]
1212

13+
[[bin]]
14+
name = "create_cf_db"
15+
path = "bin/create-cf-db/main.rs"
16+
test = false
17+
1318
[dependencies]
1419
rocksdb = { path = "rust-rocksdb" }
1520
librocksdb-sys = { path = "rust-rocksdb/librocksdb-sys" }

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ These two purposes operate in different modes:
2929
- **Raw mode** (`options=Options(raw_mode=True)`),
3030
which allows storing only `bytes`.
3131

32+
## Easily inspect RocksDB created by C++, Java, or Other Languages
33+
34+
```python
35+
from rocksdict import Rdict
36+
37+
# This will automatically load latest options and column families.
38+
# Note also that this is automatically RAW MODE,
39+
# as it knows that the db is not created by RocksDict.
40+
db = Rdict("db_path")
41+
42+
# list column families
43+
cfs = Rdict.list_cf("db_path")
44+
print(cfs)
45+
46+
# use one of the column families
47+
cf1 = db.get_column_family(cfs[1])
48+
49+
# iterate through all key-value pairs in cf1
50+
for k, v in cf1.items():
51+
print(f"{k} -> {v}")
52+
53+
# iterate through all wide columns in cf1
54+
for k, v in cf1.entities():
55+
print(f"{k} -> {v}")
56+
```
57+
3258
## Examples
3359

3460
### A minimal example

bin/create-cf-db/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! for convenient testing purpose
2+
use rocksdb::{Options, DB};
3+
use std::env::args;
4+
5+
fn main() {
6+
let args = args().collect::<Vec<_>>();
7+
if args.len() < 3 {
8+
println!("usage: ./create_cf_db path cf1 cf2 cf3...");
9+
return;
10+
}
11+
12+
let path = &args[1];
13+
let mut opts = Options::default();
14+
opts.create_if_missing(true);
15+
opts.create_missing_column_families(true);
16+
DB::open_cf(&opts, path, &args[2..]).expect("failed to create db");
17+
}

0 commit comments

Comments
 (0)