pub struct SharedSqlite { /* private fields */ }Expand description
Clonable handle onto a SqliteStore’s connection pool and serialization
semaphore. Obtained via SqliteStore::shared. Holding one does not keep any
device row alive — it is purely connection plumbing.
Implementations§
Sourcepub async fn run<F, T>(&self, f: F) -> Result<T>
pub async fn run<F, T>(&self, f: F) -> Result<T>
Run f on a pooled connection from a blocking thread, holding one of the
store’s serialization permits for the duration. The closure owns error
mapping into StoreError so callers can also run non-query work
(e.g. their own embedded migrations) through the same choke point.
This is the write path: everything that can modify the database belongs
here, because the permit is what keeps two writers off SQLite at once.
For work that only reads, read skips that queue.
Sourcepub async fn read<F, T>(&self, f: F) -> Result<T>
pub async fn read<F, T>(&self, f: F) -> Result<T>
Run a read-only f without queueing behind the write permit.
WAL lets readers run alongside the single writer, which is the whole reason a slow query should not be able to stall the rest of a session. Reads still take a permit — one per reader connection — so the number of blocking threads stays bounded by the pool.
f runs inside a deferred transaction, so every statement in it sees
one snapshot. The write permit used to supply that for free — while a
read held it the writer could not commit between its statements — and a
reader that resolves a chat’s identity keys and then queries by them, or
collects search hits and then hydrates them, would otherwise straddle
two committed states and come back short. A deferred transaction over
read-only statements never asks for the write lock, so it pins the
snapshot without contending with the writer.
Only correct for statements that cannot write. A write sent through here
escapes the serialization the store relies on and can deadlock against
the real writer on the transaction upgrade, which busy_timeout cannot
resolve. When a store has no reader connections configured
(SqliteStoreConfig::read_pool_size
left at 0) this queues on the write permit exactly like
run, so it is always safe to call — it simply buys no
concurrency until the embedder opts in.
Trait Implementations§
Source§fn clone(&self) -> SharedSqlite
fn clone(&self) -> SharedSqlite
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more