Skip to content

Commit

Permalink
Remove manual postgres language injections
Browse files Browse the repository at this point in the history
  • Loading branch information
PolpOnline committed Jan 17, 2025
1 parent aeb2aa1 commit d5031ce
Show file tree
Hide file tree
Showing 14 changed files with 2 additions and 21 deletions.
6 changes: 2 additions & 4 deletions src/backend/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ impl AuthnBackend for LoginBackend {
) -> Result<Option<Self::User>, Self::Error> {
let user: Option<Self::User> = sqlx::query_as!(
User,
// language=PostgreSQL
r#"
SELECT * FROM "user" WHERE email = $1
"#,
SELECT * FROM "user" WHERE email = $1
"#,
creds.email
)
.fetch_optional(&self.db)
Expand All @@ -106,7 +105,6 @@ impl AuthnBackend for LoginBackend {
async fn get_user(&self, user_id: &UserId<Self>) -> Result<Option<Self::User>, Self::Error> {
let user = sqlx::query_as!(
User,
// language=PostgreSQL
r#"
SELECT * FROM "user" WHERE id = $1
"#,
Expand Down
2 changes: 0 additions & 2 deletions src/backend/src/web/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub async fn re_auth_after_sign_up(

pub async fn get_user_existence(email: String, auth_session: AuthSession) -> bool {
let user = sqlx::query!(
// language=PostgreSQL
r#"
SELECT email
FROM "user"
Expand Down Expand Up @@ -152,7 +151,6 @@ pub async fn sign_up(

let user = sqlx::query_as!(
User,
// language=PostgreSQL
r#"
INSERT INTO "user" (email, password, timezone, language)
VALUES ($1, $2, $3, $4)
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/add_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub async fn add_system(
};

match sqlx::query!(
// language=PostgreSQL
r#"
INSERT INTO system (id, name, user_id, frequency, starts_at, down_after, visibility)
VALUES ($1, $2, $3, $4, $5, $6, $7)
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/change_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub async fn change_visibility(
}

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE system SET visibility = ($1) WHERE id = $2
"#,
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/delete_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub async fn delete_system(
}

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE system SET deleted = true WHERE id = $1
"#,
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/edit_system_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub async fn edit_system_name(
}

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE system SET name = ($1) WHERE id = $2
"#,
Expand Down
2 changes: 0 additions & 2 deletions src/backend/src/web/protected/list_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pub async fn list_systems(

let db_systems = match sqlx::query_as!(
SystemRecord,
// language=PostgreSQL
r#"
SELECT id,
name,
Expand Down Expand Up @@ -200,7 +199,6 @@ impl SystemData {

let db_instants = match sqlx::query_as!(
PingRecord,
// language=PostgreSQL
r#"
SELECT * FROM ping WHERE system_id = $1
AND timestamp < $2
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/user/change_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub async fn change_language(
}

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE "user" SET language = $1 WHERE id = $2
"#,
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/user/change_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub async fn change_password(
};

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE "user" SET password = $1 WHERE id = $2
"#,
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/user/change_timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub async fn change_timezone(
};

match sqlx::query!(
// language=PostgreSQL
r#"
UPDATE "user" SET timezone = $1 WHERE id = $2
"#,
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/protected/user/get_current_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub async fn get_current_settings(auth_session: AuthSession) -> impl IntoRespons
};

let current_settings = match sqlx::query!(
// language=PostgreSQL
r#"
SELECT timezone, language FROM "user" WHERE id = $1
"#,
Expand Down
2 changes: 0 additions & 2 deletions src/backend/src/web/public/ping_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub async fn ping_status(Path(id): Path<Uuid>, auth_session: AuthSession) -> imp

// Check if the system exists and is not deleted
if sqlx::query!(
// language=PostgreSQL
r#"
SELECT id FROM system WHERE id = $1 AND deleted = false
"#,
Expand All @@ -36,7 +35,6 @@ pub async fn ping_status(Path(id): Path<Uuid>, auth_session: AuthSession) -> imp

// Insert the ping into the database and reset the down_sent_email flag
sqlx::query!(
// language=PostgreSQL
r#"
WITH updated AS (
UPDATE system
Expand Down
1 change: 0 additions & 1 deletion src/backend/src/web/public/public_systems/get_public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub async fn get_public(

let db_system = match sqlx::query_as!(
SystemRecord,
// language=PostgreSQL
r#"
SELECT id, name, user_id, frequency, starts_at, deleted, down_after, down_sent_email, visibility AS "visibility: Visibility"
FROM system WHERE id = $1 AND visibility = 'public'
Expand Down
2 changes: 0 additions & 2 deletions src/backend/src/workers/email_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ impl Worker<()> for EmailWorker {
// Finalize by setting the down_sent_email flag to true for all systems that
// have been sent an email
sqlx::query!(
// language=PostgreSQL
r#"
UPDATE system
SET down_sent_email = TRUE
Expand Down Expand Up @@ -176,7 +175,6 @@ async fn query_down_services(db: &PgPool) -> GenericResult<Vec<EmailData>> {
// Query all systems that are down for longer than the down_after interval for
// which an email has not been sent
let rows = sqlx::query!(
// language=PostgreSQL
r#"
SELECT s.id AS system_id,
s.name AS system_name,
Expand Down

0 comments on commit d5031ce

Please sign in to comment.