use chrono::{DateTime, Local, NaiveDateTime, TimeZone}; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, SqlitePool}; #[derive(FromRow, Debug, Serialize, Deserialize)] pub struct Notification { pub id: i64, pub user_id: i64, pub message: String, pub read_at: NaiveDateTime, pub category: String, } impl Notification { //pub async fn create(db: &SqlitePool, msg: String) -> bool { // sqlx::query!("INSERT INTO log(msg) VALUES (?)", msg,) // .execute(db) // .await // .is_ok() //} async fn for_user(db: &SqlitePool, user: &User) -> Vec { sqlx::query_as!( Log, " SELECT id, user_id, message, read_at, category FROM notification WHERE user_id = {} ", user.id ) .fetch_all(db) .await .unwrap() } }