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 -- Your SQL goes here
CREATE TABLE users ( CREATE TABLE users (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
username VARCHAR(32), username VARCHAR(32) UNIQUE NOT NULL,
is_active BOOLEAN DEFAULT TRUE, is_active BOOLEAN DEFAULT TRUE NOT NULL,
created_at TIMESTAMPTZ DEFAULT now(), created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT NULL updated_at TIMESTAMPTZ DEFAULT NULL
); );

View File

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

View File

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