Untitled

mail@pastecode.io avatar
unknown
rust
2 years ago
1.2 kB
2
Indexable
Never
use std::env;
use rocksdb::{ColumnFamilyDescriptor, DB, IteratorMode, Options};

fn col_name(col: i32) -> String {
    format!("col{}", col)
}

fn main() {
    println!("Hello, RocksDB!");
    let args: Vec<String> = env::args().collect();
    let path = if args.len() > 1 {
        args.get(1).unwrap().clone()
    } else {
        String::from("./data")
    };
    println!("data dir={}", &path);

    let opts = Options::default();

    let mut cfs:Vec<ColumnFamilyDescriptor> = Vec::new();
    for col in  33..34 {
        cfs.push(
            rocksdb::ColumnFamilyDescriptor::new(
                col_name(col),
                opts.clone()
            ));
    }

    let db = DB::open_cf_descriptors_read_only(
        &opts,
        &path,
        cfs,
        false,
    ).unwrap();

    rocksdb::ColumnFamilyDescriptor::new("col33", opts);

    let iter = db.iterator(IteratorMode::Start);
    for (key, value) in iter {
        println!("Saw {:?} {:?}", key, value);
        let k = String::from_utf8(key.to_vec()).unwrap();
        let v = String::from_utf8(value.to_vec()).unwrap();
        println!("Saw {:?} {:?}", k, v);
    }

    let _ = DB::destroy(&Options::default(), &path);
}