mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Gardening + docs improvals
This commit is contained in:
parent
633d5b0d64
commit
32600ff8f6
2 changed files with 30 additions and 30 deletions
|
@ -7,7 +7,7 @@ To change the source code, fork the `dev` branch of this repository and work ins
|
|||
```
|
||||
cargo clippy --all --all-features --all-targets
|
||||
cargo test --all
|
||||
cargo doc --open --all-features
|
||||
RUSTDOCFLAGS="--cfg docsrs" cargo doc --open --all-features
|
||||
# Using nightly rustfmt
|
||||
cargo +nightly fmt --all -- --check
|
||||
```
|
||||
|
|
|
@ -10,6 +10,12 @@ use std::{
|
|||
};
|
||||
use thiserror::Error;
|
||||
|
||||
/// A persistent storage based on [SQLite](https://www.sqlite.org/).
|
||||
pub struct SqliteStorage<S> {
|
||||
pool: SqlitePool,
|
||||
serializer: S,
|
||||
}
|
||||
|
||||
/// An error returned from [`SqliteStorage`].
|
||||
///
|
||||
/// [`SqliteStorage`]: struct.SqliteStorage.html
|
||||
|
@ -24,17 +30,6 @@ where
|
|||
SqliteError(#[from] sqlx::Error),
|
||||
}
|
||||
|
||||
/// A persistent storage based on [SQLite](https://www.sqlite.org/).
|
||||
pub struct SqliteStorage<S> {
|
||||
pool: SqlitePool,
|
||||
serializer: S,
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct DialogueDBRow {
|
||||
dialogue: Vec<u8>,
|
||||
}
|
||||
|
||||
impl<S> SqliteStorage<S> {
|
||||
pub async fn open(
|
||||
path: &str,
|
||||
|
@ -57,24 +52,6 @@ CREATE TABLE IF NOT EXISTS teloxide_dialogues (
|
|||
}
|
||||
}
|
||||
|
||||
async fn get_dialogue(
|
||||
pool: &SqlitePool,
|
||||
chat_id: i64,
|
||||
) -> Result<Option<Box<Vec<u8>>>, sqlx::Error> {
|
||||
Ok(
|
||||
match sqlx::query_as::<_, DialogueDBRow>(
|
||||
"SELECT dialogue FROM teloxide_dialogues WHERE chat_id = ?",
|
||||
)
|
||||
.bind(chat_id)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
{
|
||||
Some(r) => Some(Box::new(r.dialogue)),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
impl<S, D> Storage<D> for SqliteStorage<S>
|
||||
where
|
||||
S: Send + Sync + Serializer<D> + 'static,
|
||||
|
@ -135,3 +112,26 @@ where
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct DialogueDBRow {
|
||||
dialogue: Vec<u8>,
|
||||
}
|
||||
|
||||
async fn get_dialogue(
|
||||
pool: &SqlitePool,
|
||||
chat_id: i64,
|
||||
) -> Result<Option<Box<Vec<u8>>>, sqlx::Error> {
|
||||
Ok(
|
||||
match sqlx::query_as::<_, DialogueDBRow>(
|
||||
"SELECT dialogue FROM teloxide_dialogues WHERE chat_id = ?",
|
||||
)
|
||||
.bind(chat_id)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
{
|
||||
Some(r) => Some(Box::new(r.dialogue)),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue