|
|
|
@ -795,6 +795,16 @@ impl Writable for DB { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl WriteBatch { |
|
|
|
|
pub fn len(&self) -> usize { |
|
|
|
|
unsafe { rocksdb_ffi::rocksdb_writebatch_count(self.inner) as usize } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool { |
|
|
|
|
self.len() == 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for WriteBatch { |
|
|
|
|
fn default() -> WriteBatch { |
|
|
|
|
WriteBatch { |
|
|
|
@ -1022,7 +1032,11 @@ fn writebatch_works() { |
|
|
|
|
// test put
|
|
|
|
|
let batch = WriteBatch::default(); |
|
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
|
assert_eq!(batch.len(), 0); |
|
|
|
|
assert!(batch.is_empty()); |
|
|
|
|
let _ = batch.put(b"k1", b"v1111"); |
|
|
|
|
assert_eq!(batch.len(), 1); |
|
|
|
|
assert!(!batch.is_empty()); |
|
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
|
let p = db.write(batch); |
|
|
|
|
assert!(p.is_ok()); |
|
|
|
@ -1033,6 +1047,8 @@ fn writebatch_works() { |
|
|
|
|
// test delete
|
|
|
|
|
let batch = WriteBatch::default(); |
|
|
|
|
let _ = batch.delete(b"k1"); |
|
|
|
|
assert_eq!(batch.len(), 1); |
|
|
|
|
assert!(!batch.is_empty()); |
|
|
|
|
let p = db.write(batch); |
|
|
|
|
assert!(p.is_ok()); |
|
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
|