Skip to content

Sqlx 0.7 update #2604

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

Closed
wants to merge 10 commits into from
Closed
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
3 changes: 1 addition & 2 deletions contrib/db_pools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ deadpool_redis = ["deadpool-redis", "deadpool"]
sqlx_mysql = ["sqlx", "sqlx/mysql"]
sqlx_postgres = ["sqlx", "sqlx/postgres"]
sqlx_sqlite = ["sqlx", "sqlx/sqlite"]
sqlx_mssql = ["sqlx", "sqlx/mssql"]
sqlx_macros = ["sqlx/macros"]
# diesel features
diesel_postgres = ["diesel-async/postgres", "diesel-async/deadpool", "diesel", "deadpool"]
Expand Down Expand Up @@ -72,7 +71,7 @@ default-features = false
optional = true

[dependencies.sqlx]
version = "0.6"
version = "0.7"
default-features = false
features = ["runtime-tokio-rustls"]
optional = true
Expand Down
11 changes: 4 additions & 7 deletions contrib/db_pools/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
//! #[get("/<id>")]
//! async fn read(mut db: Connection<Logs>, id: i64) -> Option<Log> {
//! sqlx::query("SELECT content FROM logs WHERE id = ?").bind(id)
//! .fetch_one(&mut *db).await
//! .fetch_one(&mut **db).await
//! .and_then(|r| Ok(Log(r.try_get(0)?)))
//! .ok()
//! }
Expand Down Expand Up @@ -113,23 +113,20 @@
//! On shutdown, new connections are denied. Shutdown _does not_ wait for
//! connections to be returned.
//!
//! ## `sqlx` (v0.6)
//! ## `sqlx` (v0.7)
//!
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
//! |----------|-----------------|----------------------|------------------------------------------|
//! | Postgres | `sqlx_postgres` | [`sqlx::PgPool`] | [`sqlx::pool::PoolConnection<Postgres>`] |
//! | MySQL | `sqlx_mysql` | [`sqlx::MySqlPool`] | [`sqlx::pool::PoolConnection<MySql>`] |
//! | SQLite | `sqlx_sqlite` | [`sqlx::SqlitePool`] | [`sqlx::pool::PoolConnection<Sqlite>`] |
//! | MSSQL | `sqlx_mssql` | [`sqlx::MssqlPool`] | [`sqlx::pool::PoolConnection<Mssql>`] |
//!
//! [`sqlx::PgPool`]: https://docs.rs/sqlx/0.6/sqlx/type.PgPool.html
//! [`sqlx::MySqlPool`]: https://docs.rs/sqlx/0.6/sqlx/type.MySqlPool.html
//! [`sqlx::SqlitePool`]: https://docs.rs/sqlx/0.6/sqlx/type.SqlitePool.html
//! [`sqlx::MssqlPool`]: https://docs.rs/sqlx/0.6/sqlx/type.MssqlPool.html
//! [`sqlx::pool::PoolConnection<Postgres>`]: https://docs.rs/sqlx/0.6/sqlx/pool/struct.PoolConnection.html
//! [`sqlx::pool::PoolConnection<MySql>`]: https://docs.rs/sqlx/0.6/sqlx/pool/struct.PoolConnection.html
//! [`sqlx::pool::PoolConnection<Sqlite>`]: https://docs.rs/sqlx/0.6/sqlx/pool/struct.PoolConnection.html
//! [`sqlx::pool::PoolConnection<Mssql>`]: https://docs.rs/sqlx/0.6/sqlx/pool/struct.PoolConnection.html
//!
//! On shutdown, new connections are denied. Shutdown waits for connections to
//! be returned.
Expand Down Expand Up @@ -163,9 +160,9 @@
//!
//! ```toml
//! [dependencies.sqlx]
//! version = "0.6"
//! version = "0.7"
//! default-features = false
//! features = ["macros", "offline", "migrate"]
//! features = ["macros", "migrate"]
//!
//! [dependencies.rocket_db_pools]
//! version = "=0.1.0-rc.3"
Expand Down
4 changes: 2 additions & 2 deletions contrib/db_pools/lib/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ mod sqlx {
let mut opts = config.url.parse::<Options<D>>().map_err(Error::Init)?;
specialize(&mut opts, &config);

opts.disable_statement_logging();
opts = opts.disable_statement_logging();
if let Ok(level) = figment.extract_inner::<LogLevel>(rocket::Config::LOG_LEVEL) {
if !matches!(level, LogLevel::Normal | LogLevel::Off) {
opts.log_statements(level.into())
opts = opts.log_statements(level.into())
.log_slow_statements(level.into(), Duration::default());
}
}
Expand Down
7 changes: 0 additions & 7 deletions contrib/db_pools/lib/tests/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ check_types_match!(
sqlx::pool::PoolConnection<sqlx::Sqlite>,
);

check_types_match!(
"sqlx_mssql",
sqlx_mssql,
sqlx::MssqlPool,
sqlx::pool::PoolConnection<sqlx::Mssql>,
);

check_types_match!(
"mongodb",
mongodb,
Expand Down
4 changes: 2 additions & 2 deletions contrib/sync_db_pools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ diesel = { version = "2.0.0", default-features = false, optional = true }
postgres = { version = "0.19", optional = true }
r2d2_postgres = { version = "0.18", optional = true }

rusqlite = { version = "0.27.0", optional = true }
r2d2_sqlite = { version = "0.20.0", optional = true }
rusqlite = { version = "0.29.0", optional = true }
r2d2_sqlite = { version = "0.22.0", optional = true }

memcache = { version = "0.15", optional = true }
r2d2-memcache = { version = "0.6", optional = true }
Expand Down
6 changes: 6 additions & 0 deletions core/codegen/tests/ui-fail-stable/from_form.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ help: the type constructed contains `{integer}` due to the type of the argument
| ^^^ this argument influences the type of `Some`
note: tuple variant defined here
--> $RUST/core/src/option.rs
|
| Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^

error[E0308]: mismatched types
--> tests/ui-fail-stable/from_form.rs:203:33
Expand All @@ -542,6 +545,9 @@ help: the type constructed contains `&'static str` due to the type of the argume
| this argument influences the type of `Some`
note: tuple variant defined here
--> $RUST/core/src/option.rs
|
| Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^

error[E0277]: the trait bound `bool: From<&str>` is not satisfied
--> tests/ui-fail-stable/from_form.rs:209:23
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/databases/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ diesel = "2"
diesel_migrations = "2"

[dependencies.sqlx]
version = "0.6.0"
version = "0.7.0"
default-features = false
features = ["macros", "offline", "migrate"]
features = ["macros", "migrate"]

[dependencies.rocket_db_pools]
path = "../../contrib/db_pools/lib/"
Expand Down
10 changes: 5 additions & 5 deletions examples/databases/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Post {
async fn create(mut db: Connection<Db>, post: Json<Post>) -> Result<Created<Json<Post>>> {
// There is no support for `RETURNING`.
sqlx::query!("INSERT INTO posts (title, text) VALUES (?, ?)", post.title, post.text)
.execute(&mut *db)
.execute(&mut **db)
.await?;

Ok(Created::new("/").body(post))
Expand All @@ -35,7 +35,7 @@ async fn create(mut db: Connection<Db>, post: Json<Post>) -> Result<Created<Json
#[get("/")]
async fn list(mut db: Connection<Db>) -> Result<Json<Vec<i64>>> {
let ids = sqlx::query!("SELECT id FROM posts")
.fetch(&mut *db)
.fetch(&mut **db)
.map_ok(|record| record.id)
.try_collect::<Vec<_>>()
.await?;
Expand All @@ -46,7 +46,7 @@ async fn list(mut db: Connection<Db>) -> Result<Json<Vec<i64>>> {
#[get("/<id>")]
async fn read(mut db: Connection<Db>, id: i64) -> Option<Json<Post>> {
sqlx::query!("SELECT id, title, text FROM posts WHERE id = ?", id)
.fetch_one(&mut *db)
.fetch_one(&mut **db)
.map_ok(|r| Json(Post { id: Some(r.id), title: r.title, text: r.text }))
.await
.ok()
Expand All @@ -55,15 +55,15 @@ async fn read(mut db: Connection<Db>, id: i64) -> Option<Json<Post>> {
#[delete("/<id>")]
async fn delete(mut db: Connection<Db>, id: i64) -> Result<Option<()>> {
let result = sqlx::query!("DELETE FROM posts WHERE id = ?", id)
.execute(&mut *db)
.execute(&mut **db)
.await?;

Ok((result.rows_affected() == 1).then(|| ()))
}

#[delete("/")]
async fn destroy(mut db: Connection<Db>) -> Result<()> {
sqlx::query!("DELETE FROM posts").execute(&mut *db).await?;
sqlx::query!("DELETE FROM posts").execute(&mut **db).await?;

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function test_contrib() {
sqlx_mysql
sqlx_postgres
sqlx_sqlite
sqlx_mssql
mongodb
diesel_mysql
diesel_postgres
Expand Down
6 changes: 3 additions & 3 deletions site/guide/6-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ in three simple steps:
#[get("/<id>")]
async fn read(mut db: Connection<Logs>, id: i64) -> Option<String> {
sqlx::query("SELECT content FROM logs WHERE id = ?").bind(id)
.fetch_one(&mut *db).await
.fetch_one(&mut **db).await
.and_then(|r| Ok(r.try_get(0)?))
.ok()
}
Expand Down Expand Up @@ -294,9 +294,9 @@ features enabled in `Cargo.toml`:

```toml
[dependencies.sqlx]
version = "0.6"
version = "0.7"
default-features = false
features = ["macros", "offline", "migrate"]
features = ["macros", "migrate"]

[dependencies.rocket_db_pools]
version = "=0.1.0-rc.3"
Expand Down