Skip to main content

columns

Function columns 

Source
pub fn columns(attachment: Option<&Attachment>) -> [Param; 4]
Expand description

Builds the query parameters for the four columns of one attachment, in column order.

The order is <name>_key, <name>_filename, <name>_content_type, <name>_size; None binds four NULLs (an optional attachment left empty). Generated create functions extend their params! with it. Reading the columns back needs no helper: Attachment deserializes from a row with key, filename, content_type and size columns.

ยงExamples

use ocre::{params, storage::{self, Attachment}};

let avatar = Attachment { key: "k".into(), filename: "a.png".into(), content_type: "image/png".into(), size: 3 };
let mut values = params!["Ada"];
values.extend(storage::columns(Some(&avatar)));
assert_eq!(values, params!["Ada", "k", "a.png", "image/png", 3_i64]);

let empty = storage::columns(None);
assert_eq!(empty[..], params![None::<i64>, None::<i64>, None::<i64>, None::<i64>]);