pub fn column_changes(change: Option<Option<&Attachment>>) -> [Param; 5]Expand description
Builds the parameters of an UPDATE of one attachment’s columns: a change flag, then the four columns.
None keeps the stored file (flag false, four NULLs that the SQL
ignores), Some(None) clears the columns (flag true, four NULLs),
Some(Some(file)) points them to file. The generated SQL reads
avatar_key = CASE WHEN ?1 THEN ?2 ELSE avatar_key END, ..., so one
statement handles “unchanged”, “removed” and “replaced” without building
SQL at runtime. Deleting the replaced object is up to the caller
(delete_attachments, after the write succeeds).
§Examples
use ocre::{params, storage::{self, Attachment}};
let photo = Attachment { key: "k".into(), filename: "a.png".into(), content_type: "image/png".into(), size: 3 };
assert_eq!(storage::column_changes(Some(Some(&photo))), params![true, "k", "a.png", "image/png", 3_i64][..]);
let null = None::<i64>;
assert_eq!(storage::column_changes(Some(None))[..], params![true, null, null, null, null]);
assert_eq!(storage::column_changes(None)[0], params![false][0]);