pub struct SqliteUpdateRouter { /* private fields */ }__sqlite-shared only.Expand description
Routes SQLite row-change events to per-table callbacks, selected by typed
table! markers.
SQLite allows only one update hook per connection. This router is a single
value the caller composes and installs into that one slot with
on_update, so the dispatch table is
explicit rather than hidden connection state. Build it with on
and on_any, then install it:
use diesel::prelude::*;
use diesel::sqlite::{SqliteConnection, SqliteChangeOps, SqliteUpdateRouter};
use std::sync::{Arc, Mutex};
diesel::table! { users (id) { id -> Integer, name -> Text, } }
let inserted = Arc::new(Mutex::new(Vec::new()));
let captured = inserted.clone();
conn.on_update(
SqliteUpdateRouter::new()
.on(users::table, SqliteChangeOps::INSERT, move |change| {
captured.lock().unwrap().push(change.rowid);
}),
);
diesel::insert_into(users::table)
.values(users::name.eq("Alice"))
.execute(conn)
.unwrap();
assert_eq!(*inserted.lock().unwrap(), vec![1]);Every matching route fires for a given event, so overlapping routes (for
example an on_any audit log alongside table-specific
handlers) all run. There are no per-route handles: to change the routes,
install a different router or call
remove_update_hook.
Implementations§
Source§impl SqliteUpdateRouter
impl SqliteUpdateRouter
Sourcepub fn on<T, F>(self, table: T, ops: SqliteChangeOps, callback: F) -> Self
pub fn on<T, F>(self, table: T, ops: SqliteChangeOps, callback: F) -> Self
Routes changes on table matching ops to callback.
table is a table type, either generated by table!
or a diesel-dynamic-schema table. The schema name is treated as database name
An unqualified table matches by table name in
any database, so a same-named table in an ATTACH-ed database also
matches. A schema-qualified table! type additionally matches the
database name, so it fires only for that attached database.
Sourcepub fn on_any<F>(self, ops: SqliteChangeOps, callback: F) -> Self
pub fn on_any<F>(self, ops: SqliteChangeOps, callback: F) -> Self
Routes changes on any table matching ops to callback.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SqliteUpdateRouter
impl !Sync for SqliteUpdateRouter
impl !UnwindSafe for SqliteUpdateRouter
impl Freeze for SqliteUpdateRouter
impl Send for SqliteUpdateRouter
impl Unpin for SqliteUpdateRouter
impl UnsafeUnpin for SqliteUpdateRouter
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
fn aggregate_distinct(self) -> AggregateDistinct<Self>where
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
fn aggregate_all(self) -> AggregateAll<Self>where
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
fn aggregate_filter<P>(self, f: P) -> AggregateFilter<Self, P>
Source§fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> AggregateOrder<Self, O>where
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> 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.