[−][src]Struct places::db::tx::coop_transaction::ChunkedCoopTransaction
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: Duration
coop: &'conn Mutex<()>
Implementations
impl<'conn> ChunkedCoopTransaction<'conn>
[src]
pub fn new(
conn: &'conn Connection,
commit_after: Duration,
coop: &'conn Mutex<()>
) -> Result<Self>
[src]
conn: &'conn Connection,
commit_after: Duration,
coop: &'conn Mutex<()>
) -> Result<Self>
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]
fn conn(&self) -> &Connection
[src]
fn set_pragma<T>(
&self,
pragma_name: &str,
pragma_value: T
) -> Result<&Self, Error> where
T: ToSql,
[src]
&self,
pragma_name: &str,
pragma_value: T
) -> Result<&Self, Error> where
T: ToSql,
fn prepare_maybe_cached(
&'conn self,
sql: &str,
cache: bool
) -> Result<MaybeCached<'conn>, Error>
[src]
&'conn self,
sql: &str,
cache: bool
) -> Result<MaybeCached<'conn>, Error>
fn execute_all(&self, stmts: &[&str]) -> Result<(), Error>
[src]
fn execute_cached<P>(&self, sql: &str, params: P) -> Result<usize, Error> where
P: IntoIterator,
<P as IntoIterator>::Item: ToSql,
[src]
P: IntoIterator,
<P as IntoIterator>::Item: ToSql,
fn execute_named_cached(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)]
) -> Result<usize, Error>
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)]
) -> Result<usize, Error>
fn query_one<T>(&self, sql: &str) -> Result<T, Error> where
T: FromSql,
[src]
T: FromSql,
fn try_query_one<T>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
cache: bool
) -> Result<Option<T>, Error> where
T: FromSql,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
cache: bool
) -> Result<Option<T>, Error> where
T: FromSql,
fn query_row_and_then_named<T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F,
cache: bool
) -> Result<T, E> where
E: From<Error>,
F: FnOnce(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F,
cache: bool
) -> Result<T, E> where
E: From<Error>,
F: FnOnce(&Row<'_>) -> Result<T, E>,
fn query_rows_and_then_named<T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Vec<T>, E> where
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Vec<T>, E> where
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
fn query_rows_and_then_named_cached<T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Vec<T>, E> where
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Vec<T>, E> where
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
fn query_rows_into<Coll, T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Coll, E> where
Coll: FromIterator<T>,
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Coll, E> where
Coll: FromIterator<T>,
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
fn query_rows_into_cached<Coll, T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Coll, E> where
Coll: FromIterator<T>,
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F
) -> Result<Coll, E> where
Coll: FromIterator<T>,
E: From<Error>,
F: FnMut(&Row<'_>) -> Result<T, E>,
fn try_query_row<T, E, F>(
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F,
cache: bool
) -> Result<Option<T>, E> where
E: From<Error>,
F: FnOnce(&Row<'_>) -> Result<T, E>,
[src]
&self,
sql: &str,
params: &[(&str, &dyn ToSql)],
mapper: F,
cache: bool
) -> Result<Option<T>, E> where
E: From<Error>,
F: FnOnce(&Row<'_>) -> Result<T, E>,
fn unchecked_transaction(&self) -> Result<UncheckedTransaction<'_>, Error>
[src]
fn unchecked_transaction_imm(&self) -> Result<UncheckedTransaction<'_>, Error>
[src]
impl<'conn> Deref for ChunkedCoopTransaction<'conn>
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,