From 832fabf8ff296896231c0d00bc42ecde779c6d5f Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 7 Jul 2023 16:30:21 +0800 Subject: [PATCH] Upgrade SQLx to v0.7 --- Cargo.toml | 12 +++++------ sea-orm-cli/Cargo.toml | 2 +- sea-orm-codegen/Cargo.toml | 2 +- src/database/transaction.rs | 42 ++++++++++++++++++------------------- src/driver/sqlx_mysql.rs | 20 +++++++++--------- src/driver/sqlx_postgres.rs | 20 +++++++++--------- src/driver/sqlx_sqlite.rs | 20 +++++++++--------- src/query/insert.rs | 2 +- 8 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc5dffa0..1bf905b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,12 +34,12 @@ tracing = { version = "0.1", default-features = false, features = ["attributes", rust_decimal = { version = "1", default-features = false, optional = true } bigdecimal = { version = "0.3", default-features = false, optional = true } sea-orm-macros = { version = "0.12.0-rc.3", path = "sea-orm-macros", default-features = false, features = ["strum"] } -sea-query = { version = "0.29.0-rc.2", features = ["thread-safe"] } -sea-query-binder = { version = "0.4.0-rc.2", default-features = false, optional = true } +sea-query = { version = "0.29.0", git = "https://github.com/seaql/sea-query", branch = "sqlx-v0.7", features = ["thread-safe"] } +sea-query-binder = { version = "0.4.0", git = "https://github.com/seaql/sea-query", branch = "sqlx-v0.7", default-features = false, optional = true } strum = { version = "0.24", default-features = false } serde = { version = "1.0", default-features = false } serde_json = { version = "1.0", default-features = false, optional = true } -sqlx = { version = "0.6", default-features = false, optional = true } +sqlx = { version = "0.7", default-features = false, optional = true } uuid = { version = "1", default-features = false, optional = true } ouroboros = { version = "0.15", default-features = false } url = { version = "2.2", default-features = false } @@ -78,7 +78,7 @@ macros = ["sea-orm-macros/derive", "sea-query/derive"] mock = [] with-json = ["serde_json", "sea-query/with-json", "chrono?/serde", "time?/serde", "uuid?/serde", "sea-query-binder?/with-json", "sqlx?/json"] with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder?/with-chrono", "sqlx?/chrono"] -with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder?/with-rust_decimal", "sqlx?/decimal"] +with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder?/with-rust_decimal", "sqlx?/rust_decimal"] with-bigdecimal = ["bigdecimal", "sea-query/with-bigdecimal", "sea-query-binder?/with-bigdecimal", "sqlx?/bigdecimal"] with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder?/with-uuid", "sqlx?/uuid"] with-time = ["time", "sea-query/with-time", "sea-query-binder?/with-time", "sqlx?/time"] @@ -102,12 +102,12 @@ runtime-async-std-rustls = [ ] runtime-actix = [] runtime-actix-native-tls = [ - "sqlx?/runtime-actix-native-tls", + "sqlx?/runtime-tokio-native-tls", "sea-query-binder?/runtime-actix-native-tls", "runtime-actix", ] runtime-actix-rustls = [ - "sqlx?/runtime-actix-rustls", + "sqlx?/runtime-tokio-rustls", "sea-query-binder?/runtime-actix-rustls", "runtime-actix", ] diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 25770b87..7a6fa081 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -39,7 +39,7 @@ dotenvy = { version = "0.15", default-features = false, optional = true } async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true } sea-orm-codegen = { version = "=0.12.0-rc.3", path = "../sea-orm-codegen", default-features = false, optional = true } sea-schema = { version = "0.12.0-rc.2" } -sqlx = { version = "0.6", default-features = false, features = ["mysql", "postgres"], optional = true } +sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true } tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] } tracing = { version = "0.1", default-features = false } url = { version = "2.2", default-features = false } diff --git a/sea-orm-codegen/Cargo.toml b/sea-orm-codegen/Cargo.toml index cb97dbf9..52757d67 100644 --- a/sea-orm-codegen/Cargo.toml +++ b/sea-orm-codegen/Cargo.toml @@ -17,7 +17,7 @@ name = "sea_orm_codegen" path = "src/lib.rs" [dependencies] -sea-query = { version = "0.29.0-rc.2", default-features = false, features = ["thread-safe"] } +sea-query = { version = "0.29.0", git = "https://github.com/seaql/sea-query", branch = "sqlx-v0.7", default-features = false, features = ["thread-safe"] } syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] } quote = { version = "1", default-features = false } heck = { version = "0.4", default-features = false } diff --git a/src/database/transaction.rs b/src/database/transaction.rs index e228a638..040b300e 100644 --- a/src/database/transaction.rs +++ b/src/database/transaction.rs @@ -310,26 +310,26 @@ impl ConnectionTrait for DatabaseTransaction { match &mut *self.conn.lock().await { #[cfg(feature = "sqlx-mysql")] - InnerConnection::MySql(conn) => { + InnerConnection::MySql(ref mut conn) => { let query = crate::driver::sqlx_mysql::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { - query.execute(conn).await.map(Into::into) + query.execute(&mut **conn).await.map(Into::into) }) .map_err(sqlx_error_to_exec_err) } #[cfg(feature = "sqlx-postgres")] - InnerConnection::Postgres(conn) => { + InnerConnection::Postgres(ref mut conn) => { let query = crate::driver::sqlx_postgres::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { - query.execute(conn).await.map(Into::into) + query.execute(&mut **conn).await.map(Into::into) }) .map_err(sqlx_error_to_exec_err) } #[cfg(feature = "sqlx-sqlite")] - InnerConnection::Sqlite(conn) => { + InnerConnection::Sqlite(ref mut conn) => { let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { - query.execute(conn).await.map(Into::into) + query.execute(&mut **conn).await.map(Into::into) }) .map_err(sqlx_error_to_exec_err) } @@ -347,17 +347,17 @@ impl ConnectionTrait for DatabaseTransaction { match &mut *self.conn.lock().await { #[cfg(feature = "sqlx-mysql")] - InnerConnection::MySql(conn) => sqlx::Executor::execute(conn, sql) + InnerConnection::MySql(ref mut conn) => sqlx::Executor::execute(&mut **conn, sql) .await .map(Into::into) .map_err(sqlx_error_to_exec_err), #[cfg(feature = "sqlx-postgres")] - InnerConnection::Postgres(conn) => sqlx::Executor::execute(conn, sql) + InnerConnection::Postgres(ref mut conn) => sqlx::Executor::execute(&mut **conn, sql) .await .map(Into::into) .map_err(sqlx_error_to_exec_err), #[cfg(feature = "sqlx-sqlite")] - InnerConnection::Sqlite(conn) => sqlx::Executor::execute(conn, sql) + InnerConnection::Sqlite(ref mut conn) => sqlx::Executor::execute(&mut **conn, sql) .await .map(Into::into) .map_err(sqlx_error_to_exec_err), @@ -379,29 +379,29 @@ impl ConnectionTrait for DatabaseTransaction { match &mut *self.conn.lock().await { #[cfg(feature = "sqlx-mysql")] - InnerConnection::MySql(conn) => { + InnerConnection::MySql(ref mut conn) => { let query = crate::driver::sqlx_mysql::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { Self::map_err_ignore_not_found( - query.fetch_one(conn).await.map(|row| Some(row.into())), + query.fetch_one(&mut **conn).await.map(|row| Some(row.into())), ) }) } #[cfg(feature = "sqlx-postgres")] - InnerConnection::Postgres(conn) => { + InnerConnection::Postgres(ref mut conn) => { let query = crate::driver::sqlx_postgres::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { Self::map_err_ignore_not_found( - query.fetch_one(conn).await.map(|row| Some(row.into())), + query.fetch_one(&mut **conn).await.map(|row| Some(row.into())), ) }) } #[cfg(feature = "sqlx-sqlite")] - InnerConnection::Sqlite(conn) => { + InnerConnection::Sqlite(ref mut conn) => { let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { Self::map_err_ignore_not_found( - query.fetch_one(conn).await.map(|row| Some(row.into())), + query.fetch_one(&mut **conn).await.map(|row| Some(row.into())), ) }) } @@ -419,33 +419,33 @@ impl ConnectionTrait for DatabaseTransaction { match &mut *self.conn.lock().await { #[cfg(feature = "sqlx-mysql")] - InnerConnection::MySql(conn) => { + InnerConnection::MySql(ref mut conn) => { let query = crate::driver::sqlx_mysql::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { query - .fetch_all(conn) + .fetch_all(&mut **conn) .await .map(|rows| rows.into_iter().map(|r| r.into()).collect()) .map_err(sqlx_error_to_query_err) }) } #[cfg(feature = "sqlx-postgres")] - InnerConnection::Postgres(conn) => { + InnerConnection::Postgres(ref mut conn) => { let query = crate::driver::sqlx_postgres::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { query - .fetch_all(conn) + .fetch_all(&mut **conn) .await .map(|rows| rows.into_iter().map(|r| r.into()).collect()) .map_err(sqlx_error_to_query_err) }) } #[cfg(feature = "sqlx-sqlite")] - InnerConnection::Sqlite(conn) => { + InnerConnection::Sqlite(ref mut conn) => { let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt); crate::metric::metric!(self.metric_callback, &stmt, { query - .fetch_all(conn) + .fetch_all(&mut **conn) .await .map(|rows| rows.into_iter().map(|r| r.into()).collect()) .map_err(sqlx_error_to_query_err) diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index ebea1b83..627dc1e7 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -49,9 +49,9 @@ impl SqlxMySqlConnector { .map_err(sqlx_error_to_conn_err)?; use sqlx::ConnectOptions; if !options.sqlx_logging { - opt.disable_statement_logging(); + opt = opt.disable_statement_logging(); } else { - opt.log_statements(options.sqlx_logging_level); + opt = opt.log_statements(options.sqlx_logging_level); } match options.pool_options().connect_with(opt).await { Ok(pool) => Ok(DatabaseConnection::SqlxMySqlPoolConnection( @@ -82,9 +82,9 @@ impl SqlxMySqlPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.execute(conn).await { + match query.execute(&mut *conn).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), } @@ -99,7 +99,7 @@ impl SqlxMySqlPoolConnection { pub async fn execute_unprepared(&self, sql: &str) -> Result { debug_print!("{}", sql); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.execute(sql).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), @@ -115,9 +115,9 @@ impl SqlxMySqlPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_one(conn).await { + match query.fetch_one(&mut *conn).await { Ok(row) => Ok(Some(row.into())), Err(err) => match err { sqlx::Error::RowNotFound => Ok(None), @@ -136,9 +136,9 @@ impl SqlxMySqlPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_all(conn).await { + match query.fetch_all(&mut *conn).await { Ok(rows) => Ok(rows.into_iter().map(|r| r.into()).collect()), Err(err) => Err(sqlx_error_to_query_err(err)), } @@ -224,7 +224,7 @@ impl SqlxMySqlPoolConnection { /// Checks if a connection to the database is still valid. pub async fn ping(&self) -> Result<(), DbErr> { - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.ping().await { Ok(_) => Ok(()), Err(err) => Err(sqlx_error_to_conn_err(err)), diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index e78aa8d8..0030763f 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -49,9 +49,9 @@ impl SqlxPostgresConnector { .map_err(sqlx_error_to_conn_err)?; use sqlx::ConnectOptions; if !options.sqlx_logging { - opt.disable_statement_logging(); + opt = opt.disable_statement_logging(); } else { - opt.log_statements(options.sqlx_logging_level); + opt = opt.log_statements(options.sqlx_logging_level); } let set_search_path_sql = options .schema_search_path @@ -97,9 +97,9 @@ impl SqlxPostgresPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.execute(conn).await { + match query.execute(&mut *conn).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), } @@ -114,7 +114,7 @@ impl SqlxPostgresPoolConnection { pub async fn execute_unprepared(&self, sql: &str) -> Result { debug_print!("{}", sql); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.execute(sql).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), @@ -130,9 +130,9 @@ impl SqlxPostgresPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_one(conn).await { + match query.fetch_one(&mut *conn).await { Ok(row) => Ok(Some(row.into())), Err(err) => match err { sqlx::Error::RowNotFound => Ok(None), @@ -151,9 +151,9 @@ impl SqlxPostgresPoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_all(conn).await { + match query.fetch_all(&mut *conn).await { Ok(rows) => Ok(rows.into_iter().map(|r| r.into()).collect()), Err(err) => Err(sqlx_error_to_query_err(err)), } @@ -239,7 +239,7 @@ impl SqlxPostgresPoolConnection { /// Checks if a connection to the database is still valid. pub async fn ping(&self) -> Result<(), DbErr> { - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.ping().await { Ok(_) => Ok(()), Err(err) => Err(sqlx_error_to_conn_err(err)), diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 5e187549..1a441990 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -53,9 +53,9 @@ impl SqlxSqliteConnector { } use sqlx::ConnectOptions; if !options.sqlx_logging { - opt.disable_statement_logging(); + opt = opt.disable_statement_logging(); } else { - opt.log_statements(options.sqlx_logging_level); + opt = opt.log_statements(options.sqlx_logging_level); } if options.get_max_connections().is_none() { options.max_connections(1); @@ -89,9 +89,9 @@ impl SqlxSqlitePoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.execute(conn).await { + match query.execute(&mut *conn).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), } @@ -106,7 +106,7 @@ impl SqlxSqlitePoolConnection { pub async fn execute_unprepared(&self, sql: &str) -> Result { debug_print!("{}", sql); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.execute(sql).await { Ok(res) => Ok(res.into()), Err(err) => Err(sqlx_error_to_exec_err(err)), @@ -122,9 +122,9 @@ impl SqlxSqlitePoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_one(conn).await { + match query.fetch_one(&mut *conn).await { Ok(row) => Ok(Some(row.into())), Err(err) => match err { sqlx::Error::RowNotFound => Ok(None), @@ -143,9 +143,9 @@ impl SqlxSqlitePoolConnection { debug_print!("{}", stmt); let query = sqlx_query(&stmt); - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { crate::metric::metric!(self.metric_callback, &stmt, { - match query.fetch_all(conn).await { + match query.fetch_all(&mut *conn).await { Ok(rows) => Ok(rows.into_iter().map(|r| r.into()).collect()), Err(err) => Err(sqlx_error_to_query_err(err)), } @@ -231,7 +231,7 @@ impl SqlxSqlitePoolConnection { /// Checks if a connection to the database is still valid. pub async fn ping(&self) -> Result<(), DbErr> { - if let Ok(conn) = &mut self.pool.acquire().await { + if let Ok(mut conn) = self.pool.acquire().await { match conn.ping().await { Ok(_) => Ok(()), Err(err) => Err(sqlx_error_to_conn_err(err)), diff --git a/src/query/insert.rs b/src/query/insert.rs index cf878dcd..3e26e011 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -347,7 +347,7 @@ where mod tests { use sea_query::OnConflict; - use crate::tests_cfg::cake::{self, ActiveModel}; + use crate::tests_cfg::cake::{self}; use crate::{ActiveValue, DbBackend, DbErr, EntityTrait, Insert, IntoActiveModel, QueryTrait}; #[test]