Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AnyQueryResult for Sqlite and MySQL #3608

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sqlx-mysql/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
5 changes: 4 additions & 1 deletion sqlx-postgres/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sqlx-postgres/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
14 changes: 14 additions & 0 deletions sqlx-sqlite/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}