Add DB#put_cf_opt for WriteOptions.

master
Ceri Storey 9 years ago
parent df6d49506b
commit a1dd3f8f22
  1. 29
      src/rocksdb.rs

@ -540,37 +540,44 @@ impl DB {
Ok(()) Ok(())
} }
} }
}
impl Writable for DB {
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> {
self.put_opt(key, value, &WriteOptions::new())
}
fn put_cf(&self, fn put_cf_opt(&self,
cf: DBCFHandle, cf: DBCFHandle,
key: &[u8], key: &[u8],
value: &[u8]) value: &[u8],
writeopts: &WriteOptions)
-> Result<(), String> { -> Result<(), String> {
unsafe { unsafe {
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create();
let mut err: *const i8 = 0 as *const i8; let mut err: *const i8 = 0 as *const i8;
let err_ptr: *mut *const i8 = &mut err; let err_ptr: *mut *const i8 = &mut err;
rocksdb_ffi::rocksdb_put_cf(self.inner, rocksdb_ffi::rocksdb_put_cf(self.inner,
writeopts.clone(), writeopts.inner,
cf, cf,
key.as_ptr(), key.as_ptr(),
key.len() as size_t, key.len() as size_t,
value.as_ptr(), value.as_ptr(),
value.len() as size_t, value.len() as size_t,
err_ptr); err_ptr);
rocksdb_ffi::rocksdb_writeoptions_destroy(writeopts);
if !err.is_null() { if !err.is_null() {
return Err(error_message(err)); return Err(error_message(err));
} }
Ok(()) Ok(())
} }
} }
}
impl Writable for DB {
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> {
self.put_opt(key, value, &WriteOptions::new())
}
fn put_cf(&self,
cf: DBCFHandle,
key: &[u8],
value: &[u8])
-> Result<(), String> {
self.put_cf_opt(cf, key, value, &WriteOptions::new())
}
fn merge(&self, key: &[u8], value: &[u8]) -> Result<(), String> { fn merge(&self, key: &[u8], value: &[u8]) -> Result<(), String> {
unsafe { unsafe {

Loading…
Cancel
Save