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

Upgrade to SQLx v0.7 #652

Merged
merged 15 commits into from
Jul 20, 2023
Merged

Upgrade to SQLx v0.7 #652

merged 15 commits into from
Jul 20, 2023

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Jul 7, 2023

PR Info

Upgrade

  • Upgrade sqlx to 0.7
  • Upgrade ipnetwork to 0.20

@billy1624 billy1624 marked this pull request as draft July 12, 2023 04:08
@billy1624 billy1624 requested a review from tyt2y3 July 13, 2023 15:36
@billy1624 billy1624 marked this pull request as ready for review July 13, 2023 15:36
@saiintbrisson
Copy link

saiintbrisson commented Jul 15, 2023

This is probably good to go now that launchbadge/sqlx#2585 passed and 0.7.1 is released

@tyt2y3
Copy link
Member

tyt2y3 commented Jul 16, 2023

Oh nice, then may be we can revert fa50aa2

@billy1624
Copy link
Member Author

billy1624 commented Jul 19, 2023

CHANGELOG of SQLx 0.7.1
https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md#071---2023-07-14

@@ -4,6 +4,7 @@ use rust_decimal::Decimal;
use sea_query::{ColumnDef, Expr, Func, Iden, MysqlQueryBuilder, OnConflict, Order, Query, Table};
use sea_query_binder::SqlxBinder;
use sqlx::{types::chrono::NaiveDateTime, MySqlPool, Row};
use std::ops::DerefMut;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We import std::ops::DerefMut into scope because we call the .deref_mut() method.

@@ -40,7 +41,7 @@ async fn main() {
.col(ColumnDef::new(Character::Created).date_time())
.build(MysqlQueryBuilder);

let result = sqlx::query(&sql).execute(&mut pool).await;
let result = sqlx::query(&sql).execute(pool.deref_mut()).await;
Copy link
Member

@tyt2y3 tyt2y3 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And use the (&mut *pool) syntax?

although to be precise it should be a conn, not a pool.

let pool = Pool::connect();
let conn = pool.acquire();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't .deref_mut() more explicit?

The (&mut *pool) seems like too much magic, especially since this is in an example

Copy link
Member Author

@billy1624 billy1624 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think .deref_mut() looks nicer. And, yes, as @rakshith-ravi said, less magic and more explicit.

Originally, I use (&mut *pool) syntax, but then I switched to .deref_mut(). Both ways did the same thing. See SeaQL/sea-orm@ee739a0 (the PR: SeaQL/sea-orm#1742), it's SeaORM but same.

- query.execute(conn).await.map(Into::into)
+ query.execute(&mut **conn).await.map(Into::into)

Isn't it look bad?

With .deref_mut()...

- query.execute(conn).await.map(Into::into)
+ query.execute(conn.deref_mut()).await.map(Into::into)

Thoughts? @tyt2y3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&mut *pool +1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Executor impls for Transaction and PoolConnection have been deleted because they cannot exist in the new crate architecture without rewriting the Executor trait entirely.
To fix this breakage, simply add a dereference where an impl Executor is expected, as they both dereference to the inner connection type which will still implement it:
&mut transaction -> &mut *transaction
&mut connection -> &mut *connection

As per https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md#breaking

@billy1624 billy1624 requested a review from tyt2y3 July 20, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants