mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-05 10:24:32 +01:00
Cargo +nightly fmt, gardening
This commit is contained in:
parent
f8a00e64d8
commit
844a198753
1 changed files with 17 additions and 16 deletions
|
@ -1,8 +1,7 @@
|
||||||
use super::{serializer::Serializer, Storage};
|
use super::{serializer::Serializer, Storage};
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::{sqlite::SqlitePool, Executor};
|
||||||
use sqlx::Executor;
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
|
@ -59,6 +58,7 @@ async fn get_dialogue(
|
||||||
pool: &SqlitePool,
|
pool: &SqlitePool,
|
||||||
chat_id: i64,
|
chat_id: i64,
|
||||||
) -> Result<Option<Box<Vec<u8>>>, sqlx::Error> {
|
) -> Result<Option<Box<Vec<u8>>>, sqlx::Error> {
|
||||||
|
Ok(
|
||||||
match sqlx::query_as::<_, DialogueDBRow>(
|
match sqlx::query_as::<_, DialogueDBRow>(
|
||||||
"SELECT dialogue FROM teloxide_dialogues WHERE chat_id = ?",
|
"SELECT dialogue FROM teloxide_dialogues WHERE chat_id = ?",
|
||||||
)
|
)
|
||||||
|
@ -66,9 +66,10 @@ async fn get_dialogue(
|
||||||
.fetch_optional(pool)
|
.fetch_optional(pool)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
Some(r) => Ok(Some(Box::new(r.dialogue))),
|
Some(r) => Some(Box::new(r.dialogue)),
|
||||||
_ => Ok(None),
|
_ => None,
|
||||||
}
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, D> Storage<D> for SqliteStorage<S>
|
impl<S, D> Storage<D> for SqliteStorage<S>
|
||||||
|
@ -84,8 +85,7 @@ where
|
||||||
chat_id: i64,
|
chat_id: i64,
|
||||||
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
|
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
match get_dialogue(&self.pool, chat_id).await? {
|
Ok(match get_dialogue(&self.pool, chat_id).await? {
|
||||||
None => Ok(None),
|
|
||||||
Some(d) => {
|
Some(d) => {
|
||||||
let prev_dialogue =
|
let prev_dialogue =
|
||||||
self.serializer.deserialize(&d).map_err(SqliteStorageError::SerdeError)?;
|
self.serializer.deserialize(&d).map_err(SqliteStorageError::SerdeError)?;
|
||||||
|
@ -93,9 +93,10 @@ where
|
||||||
.bind(chat_id)
|
.bind(chat_id)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Some(prev_dialogue))
|
Some(prev_dialogue)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ where
|
||||||
Some(d) => {
|
Some(d) => {
|
||||||
Some(self.serializer.deserialize(&d).map_err(SqliteStorageError::SerdeError)?)
|
Some(self.serializer.deserialize(&d).map_err(SqliteStorageError::SerdeError)?)
|
||||||
}
|
}
|
||||||
None => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let upd_dialogue =
|
let upd_dialogue =
|
||||||
self.serializer.serialize(&dialogue).map_err(SqliteStorageError::SerdeError)?;
|
self.serializer.serialize(&dialogue).map_err(SqliteStorageError::SerdeError)?;
|
||||||
|
|
Loading…
Reference in a new issue