Update rusqlite from 0.24 to 0.25

This commit is contained in:
link2xt
2021-05-01 06:23:06 +03:00
parent c5aef03008
commit 17ad4e99ee
10 changed files with 35 additions and 35 deletions

View File

@@ -441,14 +441,14 @@ impl ChatId {
}
async fn get_draft_msg_id(self, context: &Context) -> Result<Option<MsgId>, Error> {
context
let msg_id: Option<MsgId> = context
.sql
.query_get_value::<MsgId>(
.query_get_value(
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
paramsv![self, MessageState::OutDraft],
)
.await
.map_err(Into::into)
.await?;
Ok(msg_id)
}
pub async fn get_draft(self, context: &Context) -> Result<Option<Message>, Error> {
@@ -2371,9 +2371,9 @@ pub(crate) async fn reset_gossiped_timestamp(
/// Get timestamp of the last gossip sent in the chat.
/// Zero return value means that gossip was never sent.
pub async fn get_gossiped_timestamp(context: &Context, chat_id: ChatId) -> Result<i64, Error> {
let timestamp = context
let timestamp: Option<i64> = context
.sql
.query_get_value::<i64>(
.query_get_value(
"SELECT gossiped_timestamp FROM chats WHERE id=?;",
paramsv![chat_id],
)
@@ -2762,7 +2762,7 @@ pub async fn forward_msgs(
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
msg_ids.iter().map(|_| "?").join(",")
),
msg_ids.iter().map(|v| v as &dyn crate::ToSql).collect(),
rusqlite::params_from_iter(msg_ids),
|row| row.get::<_, MsgId>(0),
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
)

View File

@@ -499,7 +499,7 @@ impl Contact {
if update_name {
// Update the contact name also if it is used as a group name.
// This is one of the few duplicated data, however, getting the chat list is easier this way.
let chat_id = context.sql.query_get_value::<i32>(
let chat_id: Option<i32> = context.sql.query_get_value(
"SELECT id FROM chats WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)",
paramsv![Chattype::Single, isize::try_from(row_id)?]
).await?;

View File

@@ -853,7 +853,7 @@ async fn kill_ids(context: &Context, job_ids: &[u32]) -> sql::Result<()> {
);
context
.sql
.execute(q, job_ids.iter().map(|i| i as &dyn crate::ToSql).collect())
.execute(q, rusqlite::params_from_iter(job_ids))
.await?;
Ok(())
}

View File

@@ -382,7 +382,7 @@ impl Message {
),
paramsv![id],
|row| {
let text = match row.get_raw("txt") {
let text = match row.get_ref("txt")? {
rusqlite::types::ValueRef::Text(buf) => {
match String::from_utf8(buf.to_vec()) {
Ok(t) => t,

View File

@@ -165,7 +165,7 @@ impl Peerstate {
async fn from_stmt(
context: &Context,
query: &str,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
) -> Result<Option<Peerstate>> {
let peerstate = context
.sql

View File

@@ -25,10 +25,10 @@ use crate::stock_str;
#[macro_export]
macro_rules! paramsv {
() => {
Vec::new()
rusqlite::params_from_iter(Vec::<&dyn $crate::ToSql>::new())
};
($($param:expr),+ $(,)?) => {
vec![$(&$param as &dyn $crate::ToSql),+]
rusqlite::params_from_iter(vec![$(&$param as &dyn $crate::ToSql),+])
};
}
@@ -194,7 +194,7 @@ impl Sql {
pub async fn execute(
&self,
query: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
) -> Result<usize> {
let conn = self.get_conn().await?;
let res = conn.execute(query.as_ref(), params)?;
@@ -205,7 +205,7 @@ impl Sql {
pub async fn insert(
&self,
query: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
) -> anyhow::Result<usize> {
let conn = self.get_conn().await?;
conn.execute(query.as_ref(), params)?;
@@ -218,7 +218,7 @@ impl Sql {
pub async fn query_map<T, F, G, H>(
&self,
sql: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
f: F,
mut g: G,
) -> Result<H>
@@ -230,7 +230,7 @@ impl Sql {
let conn = self.get_conn().await?;
let mut stmt = conn.prepare(sql)?;
let res = stmt.query_map(&params, f)?;
let res = stmt.query_map(params, f)?;
g(res)
}
@@ -276,7 +276,7 @@ impl Sql {
pub async fn count(
&self,
query: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
) -> anyhow::Result<usize> {
let count: isize = self.query_row(query, params, |row| row.get(0)).await?;
Ok(usize::try_from(count)?)
@@ -284,7 +284,7 @@ impl Sql {
/// Used for executing `SELECT COUNT` statements only. Returns `true`, if the count is at least
/// one, `false` otherwise.
pub async fn exists(&self, sql: &str, params: Vec<&dyn crate::ToSql>) -> Result<bool> {
pub async fn exists(&self, sql: &str, params: impl rusqlite::Params) -> Result<bool> {
let count = self.count(sql, params).await?;
Ok(count > 0)
}
@@ -293,7 +293,7 @@ impl Sql {
pub async fn query_row<T, F>(
&self,
query: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
f: F,
) -> Result<T>
where
@@ -377,7 +377,7 @@ impl Sql {
pub async fn query_row_optional<T, F>(
&self,
sql: impl AsRef<str>,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
f: F,
) -> anyhow::Result<Option<T>>
where
@@ -402,7 +402,7 @@ impl Sql {
pub async fn query_get_value<T>(
&self,
query: &str,
params: Vec<&dyn crate::ToSql>,
params: impl rusqlite::Params,
) -> anyhow::Result<Option<T>>
where
T: rusqlite::types::FromSql,

View File

@@ -63,7 +63,7 @@ pub async fn lookup(
Some(chat_id) => {
context
.sql
.query_get_value::<String>(
.query_get_value(
"SELECT token FROM tokens WHERE namespc=? AND foreign_id=?;",
paramsv![namespace, chat_id],
)
@@ -73,7 +73,7 @@ pub async fn lookup(
None => {
context
.sql
.query_get_value::<String>(
.query_get_value(
"SELECT token FROM tokens WHERE namespc=? AND foreign_id=0;",
paramsv![namespace],
)