Struct teloxide::dispatching::dialogue::SqliteStorage
source · pub struct SqliteStorage<S> { /* private fields */ }
Available on crate feature
sqlite-storage
only.Expand description
A persistent dialogue storage based on SQLite.
Implementations§
source§impl<S> SqliteStorage<S>
impl<S> SqliteStorage<S>
sourcepub async fn open(
path: &str,
serializer: S
) -> Result<Arc<Self>, SqliteStorageError<Infallible>>
pub async fn open( path: &str, serializer: S ) -> Result<Arc<Self>, SqliteStorageError<Infallible>>
Examples found in repository?
examples/db_remember.rs (line 43)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
async fn main() {
pretty_env_logger::init();
log::info!("Starting DB remember bot...");
let bot = Bot::from_env();
let storage: MyStorage = if std::env::var("DB_REMEMBER_REDIS").is_ok() {
RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap().erase()
} else {
SqliteStorage::open("db.sqlite", Json).await.unwrap().erase()
};
let handler = Update::filter_message()
.enter_dialogue::<Message, ErasedStorage<State>, State>()
.branch(dptree::case![State::Start].endpoint(start))
.branch(
dptree::case![State::GotNumber(n)]
.branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
.branch(dptree::endpoint(invalid_command)),
);
Dispatcher::builder(bot, handler)
.dependencies(dptree::deps![storage])
.enable_ctrlc_handler()
.build()
.dispatch()
.await;
}
Trait Implementations§
source§impl<S, D> Storage<D> for SqliteStorage<S>where
S: Send + Sync + Serializer<D> + 'static,
D: Send + Serialize + DeserializeOwned + 'static,
<S as Serializer<D>>::Error: Debug + Display,
impl<S, D> Storage<D> for SqliteStorage<S>where S: Send + Sync + Serializer<D> + 'static, D: Send + Serialize + DeserializeOwned + 'static, <S as Serializer<D>>::Error: Debug + Display,
source§fn remove_dialogue(
self: Arc<Self>,
ChatId: ChatId
) -> BoxFuture<'static, Result<(), Self::Error>>
fn remove_dialogue( self: Arc<Self>, ChatId: ChatId ) -> BoxFuture<'static, Result<(), Self::Error>>
Returns [sqlx::Error::RowNotFound
] if a dialogue does not exist.