I'm looking to bind data through my SQL string:
#[derive(Debug, sqlx::FromRow)]
struct CurrencyExchangeRateBdd {
currency_exchange_rate_id: i64,
from_currency: String,
to_currency: String,
rate_date: Date,
rate: f64,
creation_date: OffsetDateTime,
rate_down: Option<f64>,
rate_up: Option<f64>,
}
async fn get_data(date: &String) -> Result<Vec<CurrencyExchangeRateBdd>, sqlx::Error> {
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres")
.await?;
let row = sqlx::query_as!(
CurrencyExchangeRateBdd,
"SELECT * FROM currency_exchange_rate WHERE rate_date = ?"
)
.bind(date)
.fetch_all(&pool)
.await;
row
}
I get this error:
error: error returned from database: syntax error at end of input
--> src/main.rs:50:15
|
50 | let row = sqlx::query_as!(CurrencyExchangeRateBdd,"SELECT * FROM currency_exchange_rate WHERE rate_date = ?")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
I have tried:
let row = sqlx::query_as!(CurrencyExchangeRateBdd, "SELECT * FROM currency_exchange_rate WHERE rate_date = ?", date)
Or with a $
or @
rather than ?
. I have the same as the documentation.
How I can fix this error?