diff options
author | Tyler Neely <t@jujit.su> | 2017-09-08 19:59:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-08 19:59:00 +0200 |
commit | 44020fa0a56d7ac17df6bae00dfc194d1c0cdcac (patch) | |
tree | 38872cb9672c0536cd7ea8e2b89bf4c0b26e67b5 | |
parent | 9fa920110abdfb99267061a4e261a5518e2a8f2e (diff) | |
parent | 56e5829b89b96f7ff35143d07120426628ddb8cd (diff) |
Merge pull request #141 from jeizsm/list-cf
list column families
-rw-r--r-- | src/db.rs | 26 | ||||
-rw-r--r-- | tests/test_column_family.rs | 11 |
2 files changed, 37 insertions, 0 deletions
@@ -659,6 +659,32 @@ impl DB { }) } + pub fn list_cf<P: AsRef<Path>>(opts: &Options, path: P) -> Result<Vec<String>, Error> { + let path = path.as_ref(); + let cpath = match CString::new(path.to_string_lossy().as_bytes()) { + Ok(c) => c, + Err(_) => { + return Err(Error::new("Failed to convert path to CString \ + when opening DB." + .to_owned())) + } + }; + + let mut length = 0; + + unsafe { + let ptr = ffi_try!(ffi::rocksdb_list_column_families(opts.inner, + cpath.as_ptr() as *const _, + &mut length)); + + let vec = Vec::from_raw_parts(ptr, length, length).iter().map(|&ptr| { + CString::from_raw(ptr).into_string().unwrap() + }).collect(); + Ok(vec) + } + } + + pub fn destroy<P: AsRef<Path>>(opts: &Options, path: P) -> Result<(), Error> { let cpath = CString::new(path.as_ref().to_string_lossy().as_bytes()).unwrap(); unsafe { diff --git a/tests/test_column_family.rs b/tests/test_column_family.rs index 8644aaa..9795b78 100644 --- a/tests/test_column_family.rs +++ b/tests/test_column_family.rs @@ -62,6 +62,17 @@ pub fn test_column_family() { Err(e) => panic!("failed to open db with column family: {}", e), } } + + // should be able to list a cf + { + let opts = Options::default(); + let vec = DB::list_cf(&opts, path); + match vec { + Ok(vec) => assert_eq!(vec, vec!["default", "cf1"]), + Err(e) => panic!("failed to drop column family: {}", e), + } + } + // TODO should be able to use writebatch ops with a cf { } |