diff --git a/CHANGELOG.md b/CHANGELOG.md index ec3986e..d2cf941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,12 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/ ## [Unreleased] +## [0.7.0] + +* Support for diesel 2.3 * Added support for running migrations via `AsyncMigrationHarness` +* Improved ergonomics of using query pipelining with `AsyncPgConnection` +* Added the ability to cancel queries using `AsyncMysqlConnection::cancel_token` ## [0.6.1] - 2025-07-03 @@ -103,4 +108,5 @@ in the pool should be checked if they are still valid [0.5.2]: https://github.com/weiznich/diesel_async/compare/v0.5.1...v0.5.2 [0.6.0]: https://github.com/weiznich/diesel_async/compare/v0.5.2...v0.6.0 [0.6.1]: https://github.com/weiznich/diesel_async/compare/v0.6.0...v0.6.1 -[Unreleased]: https://github.com/weiznich/diesel_async/compare/v0.6.1...main +[0.7.0]: https://github.com/weiznich/diesel_async/compare/v0.6.0...v0.7.0 +[Unreleased]: https://github.com/weiznich/diesel_async/compare/v0.7.0...main diff --git a/Cargo.toml b/Cargo.toml index e79f77f..dc33fbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diesel-async" -version = "0.6.1" +version = "0.7.0" authors = ["Georg Semmler "] edition = "2021" autotests = false @@ -110,6 +110,7 @@ rustdoc-args = ["--cfg", "docsrs", "-Z", "unstable-options", "--generate-link-to [workspace] members = [ ".", + "examples/postgres/pipelining", "examples/postgres/pooled-with-rustls", "examples/postgres/run-pending-migrations-with-rustls", "examples/sync-wrapper", diff --git a/examples/postgres/pipelining/Cargo.toml b/examples/postgres/pipelining/Cargo.toml new file mode 100644 index 0000000..9494854 --- /dev/null +++ b/examples/postgres/pipelining/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "pipelining" +version = "0.1.0" +edition = "2024" + +[dependencies] +diesel-async = { version = "0.7.0", path = "../../../", features = ["bb8", "postgres"] } +tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] } + +[dependencies.diesel] +version = "2.3.0" +default-features = false diff --git a/examples/postgres/pipelining/src/main.rs b/examples/postgres/pipelining/src/main.rs new file mode 100644 index 0000000..cb1e547 --- /dev/null +++ b/examples/postgres/pipelining/src/main.rs @@ -0,0 +1,50 @@ +use diesel::prelude::*; +use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl}; + +diesel::table! { + users { + id -> Integer, + name -> Text, + } +} + +#[derive(HasQuery, Debug)] +struct User { + id: i32, + name: String, +} + +impl User { + async fn load_all(mut conn: &AsyncPgConnection) -> QueryResult> { + Self::query().load(&mut conn).await + } + + async fn filter_by_id(mut conn: &AsyncPgConnection, id: i32) -> QueryResult> { + Self::query() + .find(id) + .get_result(&mut conn) + .await + .optional() + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let db_url = std::env::var("DATABASE_URL").expect("Env var `DATABASE_URL` not set"); + let mut conn = AsyncPgConnection::establish(&db_url).await?; + + let all_users = User::query().load(&mut conn); + let single_user = User::query().find(1).get_result(&mut conn); + + let (all_users, single_user) = tokio::try_join!(all_users, single_user)?; + println!("All users: {all_users:?}"); + println!("Single user: {single_user:?}"); + + let (all_users, single_user) = + tokio::try_join!(User::load_all(&conn), User::filter_by_id(&conn, 1))?; + + println!("All users: {all_users:?}"); + println!("Single user: {single_user:?}"); + + Ok(()) +} diff --git a/examples/postgres/pipelining/src/rust_out b/examples/postgres/pipelining/src/rust_out new file mode 100755 index 0000000..29367fa Binary files /dev/null and b/examples/postgres/pipelining/src/rust_out differ diff --git a/examples/postgres/pooled-with-rustls/Cargo.toml b/examples/postgres/pooled-with-rustls/Cargo.toml index 305e401..f0c5008 100644 --- a/examples/postgres/pooled-with-rustls/Cargo.toml +++ b/examples/postgres/pooled-with-rustls/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -diesel-async = { version = "0.6.0", path = "../../../", features = ["bb8", "postgres"] } +diesel-async = { version = "0.7.0", path = "../../../", features = ["bb8", "postgres"] } futures-util = "0.3.21" rustls = "0.23.8" rustls-platform-verifier = "0.5.0" diff --git a/examples/postgres/run-pending-migrations-with-rustls/Cargo.toml b/examples/postgres/run-pending-migrations-with-rustls/Cargo.toml index fde3837..34409b5 100644 --- a/examples/postgres/run-pending-migrations-with-rustls/Cargo.toml +++ b/examples/postgres/run-pending-migrations-with-rustls/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -diesel-async = { version = "0.6.0", path = "../../../", features = ["bb8", "postgres", "migrations"] } +diesel-async = { version = "0.7.0", path = "../../../", features = ["bb8", "postgres", "migrations"] } futures-util = "0.3.21" rustls = "0.23.8" rustls-platform-verifier = "0.5.0" diff --git a/examples/sync-wrapper/Cargo.toml b/examples/sync-wrapper/Cargo.toml index ae675ee..73870b5 100644 --- a/examples/sync-wrapper/Cargo.toml +++ b/examples/sync-wrapper/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -diesel-async = { version = "0.6.0", path = "../../", features = ["sync-connection-wrapper", "async-connection-wrapper"] } +diesel-async = { version = "0.7.0", path = "../../", features = ["sync-connection-wrapper", "async-connection-wrapper"] } futures-util = "0.3.21" tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }