When inserting, Diesel allows you to derive the Insertable
trait, which
inserts keys by name:
```rs use diesel::prelude::*;
struct User {
email: String,
password_hash: String,
// There's another field, phone
, but we are not writing it.
}
// later on...
fn write(user: User) -> QueryResult
This crate offers a similar derive trait for reading data. Diesel's
Queryable
trait reads by position rather than field name, but sometimes field
name is more convenient:
```rs use diesel::prelude::*; use dieselselectablemacro::Selectable;
struct User {
email: String,
password_hash: String,
// There's another field, phone
, but we do not need to read it.
}
// later on...
fn read(email: String) -> QueryResult
The automatically derived select
method provides the explicit fields to
Diesel, corresponding to the struct fields.