Ergonomic parameters
To make working with bind parameters, Cornucopia uses umbrella traits that allow you to pass different concrete types to the same query.
For example:
authors_by_first_name.bind(&client, &"John").all(); // This works
authors_by_first_name.bind(&client, &String::from("John")).all(); // This also works
Here's the list of umbrella traits and the concrete types they abstract over.
The pseudo trait bounds given here are very informal, but they should be easy enough to understand.
If you need to see exactly what the trait bounds are, these traits are contained in the cornucopia_client_core
crate.
StringSql
String
&str
Cow<'_, str>
Box<str>
BytesSql
Vec<u8>
&[u8]
JsonSql
(This trait is only available if the client crate has the with-serde_json-1
enabled)
serde_json::Value
postgres_types::Json
ArraySql
Vec<T>
&[T]
IterSql
Notes on IterSql
This is a wrapper type available in the client crates. It allows you to treat an iterator as an ArraySql
for the purpose of passing parameters.