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,