January 2019
Intermediate to advanced
520 pages
14h 32m
English
Let's add an implementation of the database interaction API to the lib.rs source file. We need to import the diesel crate and declare the module:
#[macro_use]extern crate diesel;mod models;mod schema;
You can see that we have added two modules: models and schema. In the implementation, we need the following types:
use diesel::{Connection, ExpressionMethods, OptionalExtension, PgConnection, QueryDsl, RunQueryDsl, insert_into};use chrono::Utc;use failure::{Error, format_err};use self::models::{Channel, Id, Membership, Message, User};use self::schema::{channels, memberships, messages, users};use std::env;
The imports include all models and all tables. We also imported the Connection trait to the establish connection, ...
Read now
Unlock full access