pub fn update<T: Serialize>(
table: &str,
key: &str,
columns: &[&str],
rows: &[T],
touch: bool,
) -> Result<Statement>Expand description
UPDATE table SET ... FROM json_each(?1) WHERE table.key = ...: a value
per row for many rows in one statement. Each row holds key (usually
id) and the columns to set; updated_at is set to now when touch.
§Errors
As insert.
§Examples
use ocre::{bulk, serde_json::json};
let rows = [json!({"id": 1, "plays": 11}), json!({"id": 2, "plays": 3})];
let update = bulk::update("tracks", "id", &["plays"], &rows, true).unwrap();
assert_eq!(
update.sql,
"UPDATE tracks SET plays = row.value ->> '$.plays', updated_at = datetime('now') \
FROM json_each(?1) AS row WHERE tracks.id = row.value ->> '$.id'"
);