sql: make all queries persistent and update to upstream sqlx

&str queries are not persistent by default.  To make queries persistent,
they have to be constructed with sqlx::query.

Upstream sqlx does not contain the change that make all queries
persistent, but it is not needed anymore. but
This commit is contained in:
link2xt
2021-04-10 21:39:24 +03:00
committed by bjoern
parent 3707471266
commit 37f68459f6
14 changed files with 114 additions and 83 deletions

View File

@@ -5,7 +5,7 @@ use std::fmt;
use anyhow::{bail, Result};
use num_traits::FromPrimitive;
use sqlx::Row;
use sqlx::{query::Query, sqlite::Sqlite, Row};
use crate::aheader::{Aheader, EncryptPreference};
use crate::chat;
@@ -173,10 +173,12 @@ impl Peerstate {
Self::from_stmt(context, query).await
}
async fn from_stmt<'e, 'q, E>(context: &Context, query: E) -> Result<Option<Peerstate>>
async fn from_stmt<'q, E>(
context: &Context,
query: Query<'q, Sqlite, E>,
) -> Result<Option<Peerstate>>
where
'q: 'e,
E: 'q + sqlx::Execute<'q, sqlx::Sqlite>,
E: 'q + sqlx::IntoArguments<'q, sqlx::Sqlite>,
{
if let Some(row) = context.sql.fetch_optional(query).await? {
// all the above queries start with this: SELECT