Skip to content

Fix the example code in README - #345

Merged
mehcode merged 1 commit into
transact-rs:masterfrom
dyoshikawa:fix-readme
May 30, 2020
Merged

Fix the example code in README#345
mehcode merged 1 commit into
transact-rs:masterfrom
dyoshikawa:fix-readme

Conversation

@dyoshikawa

@dyoshikawadyoshikawa commented May 28, 2020

Copy link
Copy Markdown
Contributor

This .await? in the example code looks unnecessary.

Example

$ rustc -V
rustc 1.43.0 (4fb7144ed 2020-04-20)
# Cargo.toml
[dependencies]
tokio = { version = "0.2", features = ["full"] }
sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "mysql" ] }
// main.rsuse sqlx::mysql::MySqlPool;use sqlx::Cursor;#[tokio::main]asyncfnmain() -> Result<(), sqlx::Error>{// Create a connection poollet pool = MySqlPool::new("mysql://root:secret@localhost:3306/foo").await.unwrap();let email = "test@example.com";// Make a simple query to return the given parameterletmut cursor = sqlx::query("SELECT * FROM users WHERE email = ?").bind(email).fetch(&pool).await.unwrap();whileletSome(row) = cursor.next().await? {// map the row into a user-defined domain type}Ok(())}

Compilation Error

error[E0277]: the trait bound `sqlx_core::mysql::cursor::MySqlCursor<'_, '_>: std::future::Future` is not satisfied
--> src/main.rs:11:22
|
11 | let mut cursor = sqlx::query("SELECT * FROM users WHERE email = ?")
| ______________________^
12 | | .bind(email)
13 | | .fetch(&pool).await.unwrap();
| |___________________________^ the trait `std::future::Future` is not implemented for `sqlx_core::mysql::cursor::MySqlCursor<'_, '_>`

@mehcode
mehcode merged commit 086dfec into transact-rs:masterMay 30, 2020
@mehcode

Copy link
Copy Markdown
Contributor

Good catch. fetch returns a stream which can't be awaited directly.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@dyoshikawa@mehcode