human
Write a query to get all the name and price from a product database in MySQL using Rust sqlx library
gpt
Here is code of a Rust sqlx query that retrieves the name and price of all products from a MySQL database:

````
use sqlx::{mysql::{MySqlPool, MySqlQueryAs}, query_as};

#[derive(Debug, sqlx::FromRow)]
struct Product {
    name: String,
    price: f64,
}

#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    // Replace "mysql://user:password@localhost/database" with your database connection string
    let pool = MySqlPool::connect("mysql://user:password@localhost/database").await?;

    let products: Vec<Product> = query_as!(Product, "SELECT name, price FROM products")
        .fetch_all(&pool)
        .await?;

    for product in products {
        println!("Name: {}, Price: {}", product.name, product.price);
    }

    Ok(())
}
````

In this example, we define a Product struct with name and price fields that correspond to the columns in the products table. We use the sqlx::query_as macro to build a query that selects the name and price columns from the products table. We then use the fetch_all method on the resulting QueryAs object to execute the query and retrieve a Vec<Product>.

Finally, we loop through the Vec<Product> and print out the name and price fields for each product.