You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use async_trait::async_trait;
use sqlx::sqlite::Sqlite;
use sqlx::mysql::MySql;
use sqlx::{Pool, Database, Executor, Connection, Execute, IntoArguments};
use sqlx::database::HasArguments;
async fn query_db<'a, DB, E>(pool: E) where
DB: Database,
E: Executor<'a, Database = DB>,
<DB as HasArguments<'a>>::Arguments: IntoArguments<'a, DB>,
{
let query = sqlx::query("select 1");
let r = query.execute(pool).await.unwrap();
// let n = r.rows_affected(); // how to get ? need Specialization for QueryResult ? there are different types in different Database, such as SqliteQueryResult, MySqlQueryResult ...
}
#[tokio::main]
async fn main() {
// generic type:
let sqlxpool = sqlx::SqlitePool::connect("sqlite:///tmp/1.sqlite3").await.unwrap();
query_db(&sqlxpool);
// specified tyep is ok:
let r = sqlx::query("select 1").execute(&sqlxpool).await.unwrap();
let n = r.rows_affected();
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am try to wrap sqlx, I want to get the affected rows, how to do ?
Cargo.toml
code:
Beta Was this translation helpful? Give feedback.
All reactions