Skip to content

Commit

Permalink
rewrite use and address implementation concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
pxp9 committed Nov 26, 2024
1 parent d7c49f1 commit b5c279a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sqlx-mysql/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::{stream, StreamExt, TryFutureExt, TryStreamExt};
pub use sqlx_core::any::{
use sqlx_core::any::{
Any, AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyStatement, AnyTypeInfo, AnyTypeInfoKind,
};
Expand Down
9 changes: 4 additions & 5 deletions sqlx-mysql/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ impl Extend<MySqlQueryResult> for MySqlQueryResult {
}
}
}

#[cfg(feature = "any")]
/// This conversion lose the last insert id data.
impl From<MySqlQueryResult> for crate::any::AnyQueryResult {
/// 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 {
crate::any::AnyQueryResult {
sqlx_core::any::AnyQueryResult {
rows_affected: done.rows_affected(),
last_insert_id: None,
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
2 changes: 1 addition & 1 deletion sqlx-sqlite/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::{StreamExt, TryFutureExt, TryStreamExt};

pub use sqlx_core::any::{
use sqlx_core::any::{
Any, AnyArguments, AnyColumn, AnyConnectOptions, AnyConnectionBackend, AnyQueryResult, AnyRow,
AnyStatement, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind,
};
Expand Down
10 changes: 7 additions & 3 deletions sqlx-sqlite/src/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ impl Extend<SqliteQueryResult> for SqliteQueryResult {
}

#[cfg(feature = "any")]
impl From<SqliteQueryResult> for crate::any::AnyQueryResult {
impl From<SqliteQueryResult> for sqlx_core::any::AnyQueryResult {
fn from(done: SqliteQueryResult) -> Self {
crate::any::AnyQueryResult {
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: Some(done.last_insert_rowid()),
last_insert_id,
}
}
}

0 comments on commit b5c279a

Please sign in to comment.