CreateTx

Struct CreateTx 

Source
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

Source

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.

Source

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.

Source

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()

Source

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.

Source

pub fn commit_to(self, final_name: &Path) -> Result<()>

Commit the transaction, but give it a specific name.

This function is necessary for compacting, normally you would just call the basic CreateTx::commit.

Source

pub fn commit(self) -> Result<()>

Commit the transaction.

On successful completion, the data is on disk (fsync is called) and the filename is renamed to lose its “.tmp” suffix.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V