pub async fn add_plant_data(client: web::Data<Client>,
plant_data: web::Json<PlantDataResponse>,) -> HttpResponse {
let _stmt = include_str!("../sql/add_plantdata.sql");
let _stmt = _stmt.replace("$table_fields", &PlantDataResponse::sql_table_fields());
let stmt = client.prepare(&_stmt).await.unwrap();
// let created_time = DateTime::parse_from_rfc3339(&plant_data.created_time.to_rfc3339())
// .unwrap_or_else(|_| Utc::now().into())
// .with_timezone(&Utc);
// println!("{}, {}, {}, {}", plant_data.plant_id, plant_data.created_time, plant_data.quality, plant_data.performance);
match client
.execute(
&stmt,
&[
&plant_data.plant_id,
&plant_data.created_time,
&plant_data.quality,
&plant_data.performance,
],
)
.await
{
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
}
}
for above code I have following schema and query
CREATE TABLE testing.plantdata (
plant_id VARCHAR(50) NOT NULL,
created_time TIMESTAMP,
quality INTEGER NOT NULL,
performance INTEGER NOT NULL
);
INSERT INTO testing.plantdata (plant_id, created_time, quality, performance)
VALUES ($1, $2, $3, $4)
But I am not able to add the data to database, what is the issue.
Please help and let me know what changes should i do.