ckb_rocksdb/ops/
writebatch.rs1use crate::ffi;
2
3use crate::{handle::Handle, Error, WriteBatch, WriteOptions};
4
5pub trait WriteOps {
6 fn write_full(&self, batch: &WriteBatch, writeopts: Option<&WriteOptions>)
7 -> Result<(), Error>;
8
9 fn write(&self, batch: &WriteBatch) -> Result<(), Error> {
10 self.write_full(batch, None)
11 }
12
13 fn write_opt(&self, batch: &WriteBatch, writeopts: &WriteOptions) -> Result<(), Error> {
14 self.write_full(batch, Some(writeopts))
15 }
16
17 fn write_without_wal(&self, batch: &WriteBatch) -> Result<(), Error> {
18 let mut wo = WriteOptions::new();
19 wo.disable_wal(true);
20 self.write_opt(batch, &wo)
21 }
22}
23
24impl<T> WriteOps for T
25where
26 T: Handle<ffi::rocksdb_t> + super::Write,
27{
28 fn write_full(
29 &self,
30 batch: &WriteBatch,
31 writeopts: Option<&WriteOptions>,
32 ) -> Result<(), Error> {
33 let mut default_writeopts = None;
34
35 let wo_handle = WriteOptions::input_or_default(writeopts, &mut default_writeopts)?;
36
37 unsafe {
38 ffi_try!(ffi::rocksdb_write(self.handle(), wo_handle, batch.handle(),));
39 Ok(())
40 }
41 }
42}