Need:
I have a solid query with named parameters to run in my backend. The query contains many reference to those parameters and, as far as i'm concerned, it's not currently possible to use named parameters query with sqlx for mysql features. So i decided to wrap my query in a stored procedure in order to use "?" and bind each parameter just one time.
Code: (Over-simplified version)
#[derive(Debug,Clone, Deserialize, Serialize, sqlx::FromRow)]
pub struct MyStruct{
a: i32
}
pub async fn get_1() -> Result<Vec<MyStruct>, Box<dyn Error>> {
let pool: Pool<MySql> = get_sql_conn().await;
let row: Vec<MyStruct> = sqlx::query_as("call z_select(?)")
.bind( 5_i32)
.fetch_all(&pool).await.unwrap();
Ok(row)
}
Procedure:
create procedure my_procedure(IN a int)
begin
select a as a;
end;
Error:
thread 'actix-rt|system:0|arbiter:0' panicked at 'called
Result::unwrap()
on anErr
value: ColumnNotFound("a")
Question:
I was first running the query without parameters (by passing the very query to "sqlx::query_as") and it was working like a charm. Why using a stored procedures results in a so much different behaviour? Is there a way to do what i need?
Sqlx dependency:
sqlx = { version = "0.5.13", features = [ "mysql", "runtime-async-std-native-tls"] }