Updating environments!

This commit is contained in:
Gregory Schier
2023-10-22 22:06:51 -07:00
parent 53d13c8172
commit c24f049dac
12 changed files with 155 additions and 52 deletions

View File

@@ -252,6 +252,27 @@ pub async fn create_environment(
get_environment(&id, pool).await
}
pub async fn update_environment(
id: &str,
data: HashMap<String, JsonValue>,
pool: &Pool<Sqlite>,
) -> Result<Environment, sqlx::Error> {
println!("DATA: {}", data.clone().len());
let json_data = Json(data);
sqlx::query!(
r#"
UPDATE environments
SET (data, updated_at) = (?, CURRENT_TIMESTAMP)
WHERE id = ?;
"#,
json_data,
id,
)
.execute(pool)
.await?;
get_environment(id, pool).await
}
pub async fn get_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environment, sqlx::Error> {
sqlx::query_as!(
Environment,