15
15
16
16
use std:: { collections:: BTreeMap , ffi:: CString , fs, iter, marker:: PhantomData , path:: Path , ptr} ;
17
17
18
- use libc:: { c_char, c_int} ;
18
+ use libc:: { c_char, c_int, size_t } ;
19
19
20
20
use crate :: {
21
- db:: DBCommon , db:: DBInner , ffi, ffi_util:: to_cpath, write_batch:: WriteBatchWithTransaction ,
22
- ColumnFamilyDescriptor , Error , OptimisticTransactionOptions , Options , ThreadMode , Transaction ,
23
- WriteOptions , DEFAULT_COLUMN_FAMILY_NAME ,
21
+ db:: { DBCommon , DBInner } ,
22
+ ffi,
23
+ ffi_util:: to_cpath,
24
+ write_batch:: WriteBatchWithTransaction ,
25
+ AsColumnFamilyRef , ColumnFamilyDescriptor , Error , OptimisticTransactionOptions , Options ,
26
+ ThreadMode , Transaction , WriteOptions , DEFAULT_COLUMN_FAMILY_NAME ,
24
27
} ;
25
28
26
29
/// A type alias to RocksDB Optimistic Transaction DB.
@@ -42,7 +45,7 @@ use crate::{
42
45
/// {
43
46
/// let db: OptimisticTransactionDB = OptimisticTransactionDB::open_default(path).unwrap();
44
47
/// db.put(b"my key", b"my value").unwrap();
45
- ///
48
+ ///
46
49
/// // create transaction
47
50
/// let txn = db.transaction();
48
51
/// txn.put(b"key2", b"value2");
@@ -290,4 +293,39 @@ impl<T: ThreadMode> OptimisticTransactionDB<T> {
290
293
wo. disable_wal ( true ) ;
291
294
self . write_opt ( batch, & wo)
292
295
}
296
+
297
+ /// Removes the database entries in the range `["from", "to")` using given write options.
298
+ pub fn delete_range_cf_opt < K : AsRef < [ u8 ] > > (
299
+ & self ,
300
+ cf : & impl AsColumnFamilyRef ,
301
+ from : K ,
302
+ to : K ,
303
+ writeopts : & WriteOptions ,
304
+ ) -> Result < ( ) , Error > {
305
+ let from = from. as_ref ( ) ;
306
+ let to = to. as_ref ( ) ;
307
+
308
+ unsafe {
309
+ ffi_try ! ( ffi:: rocksdb_delete_range_cf(
310
+ self . inner. inner( ) ,
311
+ writeopts. inner,
312
+ cf. inner( ) ,
313
+ from. as_ptr( ) as * const c_char,
314
+ from. len( ) as size_t,
315
+ to. as_ptr( ) as * const c_char,
316
+ to. len( ) as size_t,
317
+ ) ) ;
318
+ Ok ( ( ) )
319
+ }
320
+ }
321
+
322
+ /// Removes the database entries in the range `["from", "to")` using default write options.
323
+ pub fn delete_range_cf < K : AsRef < [ u8 ] > > (
324
+ & self ,
325
+ cf : & impl AsColumnFamilyRef ,
326
+ from : K ,
327
+ to : K ,
328
+ ) -> Result < ( ) , Error > {
329
+ self . delete_range_cf_opt ( cf, from, to, & WriteOptions :: default ( ) )
330
+ }
293
331
}
0 commit comments