[][src]Struct places::db::tx::coop_transaction::ChunkedCoopTransaction

pub struct ChunkedCoopTransaction<'conn> {
    tx: UncheckedTransaction<'conn>,
    commit_after: Duration,
    coop: &'conn Mutex<()>,
}

This transaction is suitable for when a transaction is used purely for performance reasons rather than for data-integrity reasons, or when it's used for integrity but held longer than strictly necessary for performance reasons (ie, when it could be multiple transactions and still guarantee integrity.) Examples of this might be for performance when updating a larger number of rows, but data integrity concerns could be addressed by using multiple, smaller transactions.

You should regularly call .maybe_commit() as part of your processing, and if the current transaction has been open for greater than some duration the transaction will be committed and another one started. You should always call .commit() at the end. Note that there is no .rollback() method as it will be very difficult to work out what was previously commited and therefore what was rolled back - if you need to explicitly roll-back, this probably isn't what you should be using. Note that SQLite might rollback for its own reasons though.

Note that this can still be used for transactions which ensure data integrity. For example, if you are processing a large group of items, and each individual item requires multiple updates, you will probably want to ensure you call .maybe_commit() after every item rather than after each individual database update.

Fields

tx: UncheckedTransaction<'conn>commit_after: Durationcoop: &'conn Mutex<()>

Implementations

impl<'conn> ChunkedCoopTransaction<'conn>[src]

pub fn new(
    conn: &'conn Connection,
    commit_after: Duration,
    coop: &'conn Mutex<()>
) -> Result<Self>
[src]

Begin a new transaction which may be split into multiple transactions for performance reasons. Cannot be nested, but this is not enforced - however, it is enforced by SQLite; use a rusqlite savepoint for nested transactions.

pub fn should_commit(&self) -> bool[src]

Returns true if the current transaction has been open for longer than the requested time, and should be committed; false otherwise. In most cases, there's no need to use this method, since maybe_commit() does so internally. It's exposed for consumers that need to run additional pre-commit logic, like cleaning up temp tables.

If this method returns true, it's guaranteed that maybe_commit() will commit the transaction.

pub fn maybe_commit(&mut self) -> Result<()>[src]

Checks to see if we have held a transaction for longer than the requested time, and if so, commits the current transaction and opens another.

fn commit_and_start_new_tx(&mut self) -> Result<()>[src]

pub fn commit(self) -> Result<()>[src]

Consumes and commits a ChunkedCoopTransaction transaction.

pub fn rollback(self) -> Result<()>[src]

Consumes and rolls a ChunkedCoopTransaction, but potentially only back to the last maybe_commit.

Trait Implementations

impl<'conn> ConnExt for ChunkedCoopTransaction<'conn>[src]

impl<'conn> Deref for ChunkedCoopTransaction<'conn>[src]

type Target = Connection

The resulting type after dereferencing.

Auto Trait Implementations

impl<'conn> !RefUnwindSafe for ChunkedCoopTransaction<'conn>

impl<'conn> !Send for ChunkedCoopTransaction<'conn>

impl<'conn> !Sync for ChunkedCoopTransaction<'conn>

impl<'conn> Unpin for ChunkedCoopTransaction<'conn>

impl<'conn> !UnwindSafe for ChunkedCoopTransaction<'conn>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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