Models

Now, we can use the generated schema to create all the necessary models that represent database records to native Rust structs. First, we have to import the NaiveDateTime type, because we have the timestamp column. Also, we have to import all tables: users, channels, memberships, and messages:

use chrono::NaiveDateTime;
use crate::schema::{users, channels, memberships, messages};

We will use the i32 type as the identifier of records, but it's better to use an alias to make its intent more clear:

pub type Id = i32;

Let's add a model to represent a record in the users table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43