From 3606cdf4ee1e6e96a953a6ae91731686f1e57200 Mon Sep 17 00:00:00 2001 From: Alex Wright Date: Sun, 1 Mar 2020 19:31:16 +0100 Subject: [PATCH] Had to make fields Optional if they're Nullable.. Makes sense. Gonna need another type for pre-commited User objects though. --- src/models.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/models.rs b/src/models.rs index cd8d5cf..609104d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,16 +1,26 @@ use chrono::{ NaiveDateTime, }; +use diesel::prelude::*; +use diesel::PgConnection; +use serde_derive::Serialize; #[derive(Queryable, Debug)] pub struct User { - pub id: Option, - pub username: String, - pub is_active: bool, + pub id: i32, + pub username: Option, + pub is_active: Option, pub created_at: Option, pub updated_at: Option, } +impl User { + pub fn get_with_username(conn: &PgConnection, name: String) -> QueryResult { + use crate::schema::users::dsl::{ username, users }; + users.filter(username.eq(&name)).first::(conn) + } +} + #[derive(Queryable)] pub struct Token { pub id: Option,