Implement AnyQueryResult for Sqlite and MySQL (#3608)

* impl AnyQueryResult for Sqlite and MySQL

* fix MySQL AnyQueryResult

* fix MySQL AnyQueryResult

* fix manifest

* rewrite `use` and address implementation concerns
This commit is contained in:
Pmarquez 2024-11-26 20:59:20 +02:00 committed by GitHub
parent 82d332f4b4
commit d4ae6ffd88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 3 deletions

View file

@ -24,3 +24,13 @@ impl Extend<MySqlQueryResult> for MySqlQueryResult {
}
}
}
#[cfg(feature = "any")]
/// This conversion attempts to save last_insert_id by converting to i64.
impl From<MySqlQueryResult> for sqlx_core::any::AnyQueryResult {
fn from(done: MySqlQueryResult) -> Self {
sqlx_core::any::AnyQueryResult {
rows_affected: done.rows_affected(),
last_insert_id: done.last_insert_id().try_into().ok(),
}
}
}

View file

@ -7,7 +7,10 @@ use futures_core::stream::BoxStream;
use futures_util::{stream, StreamExt, TryFutureExt, TryStreamExt};
use std::future;
pub use sqlx_core::any::*;
use sqlx_core::any::{
Any, AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyStatement, AnyTypeInfo, AnyTypeInfoKind,
};
use crate::type_info::PgType;
use sqlx_core::connection::Connection;

View file

@ -20,9 +20,9 @@ impl Extend<PgQueryResult> for PgQueryResult {
}
#[cfg(feature = "any")]
impl From<PgQueryResult> for crate::any::AnyQueryResult {
impl From<PgQueryResult> for sqlx_core::any::AnyQueryResult {
fn from(done: PgQueryResult) -> Self {
crate::any::AnyQueryResult {
sqlx_core::any::AnyQueryResult {
rows_affected: done.rows_affected,
last_insert_id: None,
}

View file

@ -24,3 +24,17 @@ impl Extend<SqliteQueryResult> for SqliteQueryResult {
}
}
}
#[cfg(feature = "any")]
impl From<SqliteQueryResult> for sqlx_core::any::AnyQueryResult {
fn from(done: SqliteQueryResult) -> Self {
let last_insert_id = match done.last_insert_rowid() {
0 => None,
n => Some(n),
};
sqlx_core::any::AnyQueryResult {
rows_affected: done.rows_affected(),
last_insert_id,
}
}
}