pub struct CreateTx { /* private fields */ }Expand description
Create a transaction file in the specified db directory.
Add new records with CreateTx::add_record. They must be
in sorted order.
After adding records, call CreateTx::commit which ensures
the transaction is on disk. Not calling commit will
rollback the transaction.
Implementations§
Source§impl CreateTx
impl CreateTx
Sourcepub fn new(dir: &Path) -> Result<CreateTx>
pub fn new(dir: &Path) -> Result<CreateTx>
Open a transaction file inside this specific directory.
The transaction is named “tx.XXX.tmp” where XXX is an increasing value basedo on timestamp.
On commit, the file is renamed to not have the “.tmp” suffix.
Sourcepub fn add_record(
&mut self,
key: &str,
timestamp: NaiveDateTime,
values: impl RecordBuilder,
) -> Result<(), WriteFailure>
pub fn add_record( &mut self, key: &str, timestamp: NaiveDateTime, values: impl RecordBuilder, ) -> Result<(), WriteFailure>
Add a record with the given key, timestamp, and values.
The values can be encoded with the function crate::record()
The format string is automatically inferred by the Rust-types of the values.
transaction.add_record(
"key name",
"2010-01-01T00:00:01".parse().unwrap(),
sonnerie::record("Column 1").add("Column 2").add(3i32)
).unwrap();Because &[&dyn ToRecord] also implements the crate::RecordBuilder trait,
you can also use an array to specify the types, but then less work happens at compile-time
and the performance isn’t as good:
transaction.add_record(
"key name",
"2010-01-01T00:00:01".parse().unwrap(),
&[&"Column 1" as &dyn sonnerie::ToRecord, &"Column 2", &3i32]
).unwrap();Each successive call to this function must have greater or equal values for key and timestamp.
Sourcepub fn add_record_raw(
&mut self,
key: &str,
format: &str,
data: &[u8],
) -> Result<(), WriteFailure>
pub fn add_record_raw( &mut self, key: &str, format: &str, data: &[u8], ) -> Result<(), WriteFailure>
Add a record with the given key, format, and payload.
The data must match the format (otherwise you can corrupt the database). The data also encodes the timestamp.
Each successive call to this function must have greater or equal values for key and timestamp.
Encode the data with crate::row_format::RowFormat.
This function is made available for tools that need more versaility
in how they process databases. It’s generally preferable to use CreateTx::add_record()
Sourcepub fn delete(
&mut self,
first_key: &str,
last_key: &str,
after_time: u64,
before_time: u64,
filter: &str,
) -> Result<(), WriteFailure>
pub fn delete( &mut self, first_key: &str, last_key: &str, after_time: u64, before_time: u64, filter: &str, ) -> Result<(), WriteFailure>
Delete a range of records
You can use an empty string to indicate “unbounded” and u64::MIN and u64::MAX
for the timestamps, similarly.
This function must be called as the one and only action in a transaction and then committed.
Auto Trait Implementations§
impl Freeze for CreateTx
impl !RefUnwindSafe for CreateTx
impl Send for CreateTx
impl Sync for CreateTx
impl Unpin for CreateTx
impl !UnwindSafe for CreateTx
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more