January 2019
Intermediate to advanced
520 pages
14h 32m
English
Comments will be stored in a comments table that has three fields: the id of a comment, the uid of a user, and the text of a comment:
mod schema { table! { comments { id -> Nullable<Integer>, uid -> Text, text -> Text, } }}
The Comment struct has the following declaration:
#[table_name="comments"]#[derive(Serialize, Queryable, Insertable, Debug, Clone)]pub struct Comment { pub id: Option<i32>, pub uid: String, pub text: String,}
We repeated the same field in the Comment struct and added the NewComment struct without id:
#[derive(FromForm)]pub struct NewComment { pub uid: String, pub text: String,}
And now for something new—we derive the FormForm type for the NewComment struct. It helps Rocket convert a query into ...
Read now
Unlock full access