use crate::db::get_client; use crate::errors::AppError; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] pub struct User { id: i32, email: String, password: String, } impl User { pub async fn create(user: User) -> Result { let pool = unsafe { get_client() }; let rec = sqlx::query!( r#" INSERT INTO users (email, password) VALUES ( $1, $2 ) RETURNING id "#, user.email, user.password ) .fetch_one(pool) .await?; Ok(rec.id) } pub async fn list() -> Result, AppError> { let pool = unsafe { get_client() }; let rows = sqlx::query_as!(User, r#"SELECT id, email, password FROM users"#) .fetch_all(pool) .await?; Ok(rows) } }