Fixed option/nullable fields

This commit is contained in:
Alex Wright 2020-03-01 19:36:10 +01:00
parent 3606cdf4ee
commit 035551629c
3 changed files with 6 additions and 7 deletions

View File

@ -1,8 +1,8 @@
-- Your SQL goes here
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(32),
is_active BOOLEAN DEFAULT TRUE,
username VARCHAR(32) UNIQUE NOT NULL,
is_active BOOLEAN DEFAULT TRUE NOT NULL,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT NULL
);

View File

@ -3,13 +3,12 @@ use chrono::{
};
use diesel::prelude::*;
use diesel::PgConnection;
use serde_derive::Serialize;
#[derive(Queryable, Debug)]
pub struct User {
pub id: i32,
pub username: Option<String>,
pub is_active: Option<bool>,
pub username: String,
pub is_active: bool,
pub created_at: Option<NaiveDateTime>,
pub updated_at: Option<NaiveDateTime>,
}

View File

@ -11,8 +11,8 @@ table! {
table! {
users (id) {
id -> Int4,
username -> Nullable<Varchar>,
is_active -> Nullable<Bool>,
username -> Varchar,
is_active -> Bool,
created_at -> Nullable<Timestamptz>,
updated_at -> Nullable<Timestamptz>,
}