diff options
author | cel 🌸 <cel@blos.sm> | 2023-12-13 06:50:44 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-12-13 06:50:44 +0000 |
commit | a971d8c2dc519b1db805c72cf3395c188a98dff4 (patch) | |
tree | 98e7db2d690b778b605cf8027cd14ad1eae1f053 /src/db | |
parent | a587459a1817c0fc57b46df3f9c69567e1e775b7 (diff) | |
download | pinussy-a971d8c2dc519b1db805c72cf3395c188a98dff4.tar.gz pinussy-a971d8c2dc519b1db805c72cf3395c188a98dff4.tar.bz2 pinussy-a971d8c2dc519b1db805c72cf3395c188a98dff4.zip |
switch to uuids
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/users.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/db/users.rs b/src/db/users.rs index 0fc7c64..a5759fd 100644 --- a/src/db/users.rs +++ b/src/db/users.rs @@ -1,11 +1,12 @@ use sqlx::{Pool, Postgres}; +use uuid::Uuid; use crate::users::User; use crate::Result; #[derive(Clone)] pub struct Users(Pool<Postgres>); -// code code code code code code code code code code code code code code + impl Users { pub fn new(pool: Pool<Postgres>) -> Self { Self(pool) @@ -13,7 +14,8 @@ impl Users { pub async fn create(&self, user: User) -> Result<()> { sqlx::query!( - r#"insert into users (username, password, email, bio, site, privacy, admin) values ($1, $2, $3, $4, $5, $6, $7)"#, + r#"insert into users (id, username, password, email, bio, site, privacy, admin) values ($1, $2, $3, $4, $5, $6, $7, $8)"#, + user.id, user.username, user.password, user.email, @@ -27,11 +29,11 @@ impl Users { Ok(()) } - pub async fn read(&self, user_id: i32) -> Result<User> { + pub async fn read(&self, user_id: Uuid) -> Result<User> { Ok( sqlx::query_as!( User, - "select username, password, email, bio, site, privacy as \"privacy: _\", admin from users where id = $1", + "select id, username, password, email, bio, site, privacy as \"privacy: _\", admin from users where id = $1", user_id ) .fetch_one(&self.0) @@ -43,7 +45,7 @@ impl Users { Ok( sqlx::query_as!( User, - "select username, password, email, bio, site, privacy as \"privacy: _\", admin from users where username = $1", + "select id, username, password, email, bio, site, privacy as \"privacy: _\", admin from users where username = $1", username ) .fetch_one(&self.0) @@ -51,15 +53,6 @@ impl Users { ) } - pub async fn get_id(&self, username: &str) -> Result<i32> { - Ok( - sqlx::query!("select id from users where username = $1", username) - .fetch_one(&self.0) - .await? - .id, - ) - } - pub async fn read_all(&self) -> Result<Vec<User>> { Ok(sqlx::query_as("select * from users") .fetch_all(&self.0) |