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 SQLx to v0.7 #1742

Merged
merged 13 commits into from
Jul 21, 2023
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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.4", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.29.0", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.4.0-rc.2", default-features = false, optional = true }
sea-query = { version = "0.30.0", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.5.0", default-features = false, optional = true }
strum = { version = "0.25", 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.17", default-features = false }
url = { version = "2.2", default-features = false }
Expand Down Expand Up @@ -78,7 +78,7 @@ macros = ["sea-orm-macros/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"]
Expand All @@ -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",
]
Expand Down
8 changes: 4 additions & 4 deletions sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
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.4", 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 }
sea-schema = { version = "0.14.0" }
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 }
Expand All @@ -54,9 +54,9 @@ smol = "1.2.5"
default = ["codegen", "cli", "runtime-async-std-native-tls", "async-std"]
codegen = ["sea-schema/sqlx-all", "sea-orm-codegen"]
cli = ["clap", "dotenvy"]
runtime-actix-native-tls = ["sqlx/runtime-actix-native-tls", "sea-schema/runtime-actix-native-tls"]
runtime-actix-native-tls = ["sqlx/runtime-tokio-native-tls", "sea-schema/runtime-actix-native-tls"]
runtime-async-std-native-tls = ["sqlx/runtime-async-std-native-tls", "sea-schema/runtime-async-std-native-tls"]
runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls", "sea-schema/runtime-tokio-native-tls"]
runtime-actix-rustls = ["sqlx/runtime-actix-rustls", "sea-schema/runtime-actix-rustls"]
runtime-actix-rustls = ["sqlx/runtime-tokio-rustls", "sea-schema/runtime-actix-rustls"]
runtime-async-std-rustls = ["sqlx/runtime-async-std-rustls", "sea-schema/runtime-async-std-rustls"]
runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls", "sea-schema/runtime-tokio-rustls"]
4 changes: 2 additions & 2 deletions sea-orm-cli/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub async fn run_generate_command(

let connection = connect::<MySql>(max_connections, url.as_str(), None).await?;
let schema_discovery = SchemaDiscovery::new(connection, database_name);
let schema = schema_discovery.discover().await;
let schema = schema_discovery.discover().await?;
let table_stmts = schema
.tables
.into_iter()
Expand Down Expand Up @@ -148,7 +148,7 @@ pub async fn run_generate_command(
let connection =
connect::<Postgres>(max_connections, url.as_str(), Some(schema)).await?;
let schema_discovery = SchemaDiscovery::new(connection, schema);
let schema = schema_discovery.discover().await;
let schema = schema_discovery.discover().await?;
let table_stmts = schema
.tables
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.30.0", 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 }
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
dotenvy = { version = "0.15", default-features = false, optional = true }
sea-orm = { version = "0.12.0-rc.4", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "0.12.0-rc.4", path = "../sea-orm-cli", default-features = false, optional = true }
sea-schema = { version = "0.12.0-rc.2" }
sea-schema = { version = "0.14.0" }
tracing = { version = "0.1", default-features = false, features = ["log"] }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
futures = { version = "0.3", default-features = false, features = ["std"] }
Expand Down
42 changes: 30 additions & 12 deletions src/database/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(conn) => {
let query = crate::driver::sqlx_mysql::sqlx_query(&stmt);
let conn: &mut sqlx::MySqlConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query.execute(conn).await.map(Into::into)
})
Comment on lines 312 to 318
Copy link
Member Author

Choose a reason for hiding this comment

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

@tyt2y3 the trick lol

Expand All @@ -320,6 +321,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(conn) => {
let query = crate::driver::sqlx_postgres::sqlx_query(&stmt);
let conn: &mut sqlx::PgConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query.execute(conn).await.map(Into::into)
})
Expand All @@ -328,6 +330,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(conn) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt);
let conn: &mut sqlx::SqliteConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query.execute(conn).await.map(Into::into)
})
Expand All @@ -347,20 +350,29 @@ impl ConnectionTrait for DatabaseTransaction {

match &mut *self.conn.lock().await {
#[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(conn) => sqlx::Executor::execute(conn, sql)
.await
.map(Into::into)
.map_err(sqlx_error_to_exec_err),
InnerConnection::MySql(conn) => {
let conn: &mut sqlx::MySqlConnection = &mut *conn;
sqlx::Executor::execute(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)
.await
.map(Into::into)
.map_err(sqlx_error_to_exec_err),
InnerConnection::Postgres(conn) => {
let conn: &mut sqlx::PgConnection = &mut *conn;
sqlx::Executor::execute(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)
.await
.map(Into::into)
.map_err(sqlx_error_to_exec_err),
InnerConnection::Sqlite(conn) => {
let conn: &mut sqlx::SqliteConnection = &mut *conn;
sqlx::Executor::execute(conn, sql)
.await
.map(Into::into)
.map_err(sqlx_error_to_exec_err)
}
#[cfg(feature = "mock")]
InnerConnection::Mock(conn) => {
let db_backend = conn.get_database_backend();
Expand All @@ -381,6 +393,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(conn) => {
let query = crate::driver::sqlx_mysql::sqlx_query(&stmt);
let conn: &mut sqlx::MySqlConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
Self::map_err_ignore_not_found(
query.fetch_one(conn).await.map(|row| Some(row.into())),
Expand All @@ -390,6 +403,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(conn) => {
let query = crate::driver::sqlx_postgres::sqlx_query(&stmt);
let conn: &mut sqlx::PgConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
Self::map_err_ignore_not_found(
query.fetch_one(conn).await.map(|row| Some(row.into())),
Expand All @@ -399,6 +413,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(conn) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt);
let conn: &mut sqlx::SqliteConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
Self::map_err_ignore_not_found(
query.fetch_one(conn).await.map(|row| Some(row.into())),
Expand All @@ -421,6 +436,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(conn) => {
let query = crate::driver::sqlx_mysql::sqlx_query(&stmt);
let conn: &mut sqlx::MySqlConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query
.fetch_all(conn)
Expand All @@ -432,6 +448,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(conn) => {
let query = crate::driver::sqlx_postgres::sqlx_query(&stmt);
let conn: &mut sqlx::PgConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query
.fetch_all(conn)
Expand All @@ -443,6 +460,7 @@ impl ConnectionTrait for DatabaseTransaction {
#[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(conn) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(&stmt);
let conn: &mut sqlx::SqliteConnection = &mut *conn;
crate::metric::metric!(self.metric_callback, &stmt, {
query
.fetch_all(conn)
Expand Down
16 changes: 8 additions & 8 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -82,9 +82,9 @@ impl SqlxMySqlPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand All @@ -109,9 +109,9 @@ impl SqlxMySqlPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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),
Expand All @@ -127,9 +127,9 @@ impl SqlxMySqlPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand Down
16 changes: 8 additions & 8 deletions src/driver/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,9 +97,9 @@ impl SqlxPostgresPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand All @@ -124,9 +124,9 @@ impl SqlxPostgresPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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),
Expand All @@ -142,9 +142,9 @@ impl SqlxPostgresPoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand Down
16 changes: 8 additions & 8 deletions src/driver/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -89,9 +89,9 @@ impl SqlxSqlitePoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand All @@ -116,9 +116,9 @@ impl SqlxSqlitePoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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),
Expand All @@ -134,9 +134,9 @@ impl SqlxSqlitePoolConnection {
debug_print!("{}", stmt);

let query = sqlx_query(&stmt);
let conn = &mut self.pool.acquire().await.map_err(conn_acquire_err)?;
let mut conn = self.pool.acquire().await.map_err(conn_acquire_err)?;
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)),
}
Expand Down