January 2019
Intermediate to advanced
520 pages
14h 32m
English
To represent a user stored in the users table, we will add a User struct with the following declaration:
#[derive(Debug, Identifiable, Queryable, Serialize, Deserialize)]#[table_name = "users"]pub struct User { pub id: Id, pub email: String,}
As you can see, we use the Id type for the ID column that has the SERIAL SQL type. For the email field, we use the String type, which maps to the TEXT column type in PostgreSQL.
There is also the table_name attribute to bind this struct with a table. We also derive some traits for this model—Debug for printing the model's value to a terminal, and the Serialize and Deserialize traits to make this model convertible to any serialization format. Theser are basic traits that I recommend to implement ...
Read now
Unlock full access