I am querying a database using deadpool_postgres,
but I get an error when converting to json because a field comes with null
pub async fn get_employees(client: &Client) -> Result<Vec<Employee>, AppError> {
let stmt = client
.prepare("select * from employee")
.await?;
let rowset = client
.query(&stmt, &[])
.await?
.iter()
.map(|row| {
Employee::new(
row.get("id"),
row.get("store_id"),
row.get("name"),
Some(row.get("description")), //<-- This field sometimes contains null
)
})
.collect::<Vec<Employee>>();
Ok(rowset)
}
thread 'actix-rt:worker:0' panicked at 'error retrieving column description: error deserializing column 5: a Postgres value was NULL
'
How do I capture a null value, to convert it to None?