feat: ✨ read all users for a role
feat: ✨ better reapply database migration compatibility refactor: ♻️ better naming for some functions
This commit is contained in:
parent
0a6780a1de
commit
cb4e5ec344
6 changed files with 37 additions and 13 deletions
|
@ -4,6 +4,6 @@ CREATE TABLE IF NOT EXISTS "role"(
|
|||
name VARCHAR(16) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
INSERT INTO "role"(id, name) VALUES (0, 'Ahmet Kaan Gümüş');
|
||||
INSERT INTO "role"(id, name) VALUES (1, 'Founder');
|
||||
INSERT INTO "role"(id, name) VALUES (2, 'Normal');
|
||||
INSERT INTO "role"(id, name) VALUES (0, 'Ahmet Kaan Gümüş') ON CONFLICT(id) DO UPDATE SET "name" = 'Ahmet Kaan Gümüş';
|
||||
INSERT INTO "role"(id, name) VALUES (1, 'Founder') ON CONFLICT(id) DO UPDATE SET "name" = 'Founder';
|
||||
INSERT INTO "role"(id, name) VALUES (2, 'Normal') ON CONFLICT(id) DO UPDATE SET "name" = 'Normal';
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn delete(
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all(
|
||||
pub async fn read_all_for_post(
|
||||
post_creation_time: DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<Comment>, sqlx::Error> {
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn delete(
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all(
|
||||
pub async fn read_all_for_comment(
|
||||
comment_creation_time: &DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<CommentInteraction>, sqlx::Error> {
|
||||
|
|
|
@ -73,9 +73,7 @@ pub async fn delete(
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all(
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<Post>, sqlx::Error> {
|
||||
pub async fn read_all(database_connection: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Post,
|
||||
r#"
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn delete(
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all(
|
||||
pub async fn read_all_for_post(
|
||||
post_creation_time: &DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<PostInteraction>, sqlx::Error> {
|
||||
|
|
|
@ -73,3 +73,29 @@ pub async fn delete(id: i64, database_connection: &Pool<Postgres>) -> Result<Use
|
|||
.fetch_one(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all(database_connection: &Pool<Postgres>) -> Result<Vec<User>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
User,
|
||||
r#"
|
||||
SELECT * FROM "user"
|
||||
"#,
|
||||
)
|
||||
.fetch_all(database_connection)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn read_all_for_role(
|
||||
role_id: i64,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<User>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
User,
|
||||
r#"
|
||||
SELECT * FROM "user" WHERE "role_id" = $1
|
||||
"#,
|
||||
role_id
|
||||
)
|
||||
.fetch_all(database_connection)
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue