-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Upgrade to SQLx v0.7 #652
Conversation
This is probably good to go now that launchbadge/sqlx#2585 passed and 0.7.1 is released |
Oh nice, then may be we can revert fa50aa2 |
CHANGELOG of SQLx 0.7.1 |
…cimal` is enabled (launchbadge/sqlx#2549)" This reverts commit fa50aa2.
examples/sqlx_mysql/src/main.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this
There was a problem hiding this comment.
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.
examples/sqlx_mysql/src/main.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&mut *pool
+1
There was a problem hiding this comment.
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
PR Info
Upgrade
sqlx
to 0.7ipnetwork
to 0.20