Skip to content

Commit

Permalink
backend: minor, change SQL capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Synar committed Sep 14, 2024
1 parent e62c3f5 commit 25f8c34
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 80 deletions.
24 changes: 12 additions & 12 deletions backend/src/models/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl AccessToken {
id,
title,
token,
permissions as "permissions: Json<Permissions>",
permissions AS "permissions: Json<Permissions>",
active,
0 as "last_week_visits!"
0 AS "last_week_visits!"
"#,
access_token.title,
access_token.token,
Expand Down Expand Up @@ -131,9 +131,9 @@ impl AccessToken {
id,
title,
token,
permissions as "permissions: Json<Permissions>",
permissions AS "permissions: Json<Permissions>",
active,
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') as "last_week_visits!"
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') AS "last_week_visits!"
"#,
given_id,
update.title,
Expand Down Expand Up @@ -172,9 +172,9 @@ impl AccessToken {
id,
title,
token,
permissions as "permissions: Json<Permissions>",
permissions AS "permissions: Json<Permissions>",
active,
0 as "last_week_visits!"
0 AS "last_week_visits!"
FROM access_tokens
WHERE token = $1
"#,
Expand All @@ -196,9 +196,9 @@ impl AccessToken {
id,
title,
token,
permissions as "permissions: Json<Permissions>",
permissions AS "permissions: Json<Permissions>",
active,
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') as "last_week_visits!"
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') AS "last_week_visits!"
FROM access_tokens
WHERE id = $1
"#,
Expand All @@ -217,9 +217,9 @@ impl AccessToken {
id,
title,
token,
permissions as "permissions: Json<Permissions>",
permissions AS "permissions: Json<Permissions>",
active,
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') as "last_week_visits!"
(SELECT COUNT(*) FROM access_tokens_visits WHERE token_id = id AND visited_at > NOW() - INTERVAL '1 week') AS "last_week_visits!"
FROM access_tokens
"#
)
Expand Down Expand Up @@ -262,7 +262,7 @@ impl AccessToken {
GROUP BY referrer
)
SELECT json_object_agg(referrer, total) FROM origins
), '{}') as "origins: JsonValue",
), '{}') AS "origins: JsonValue",
(
WITH date_series AS (
SELECT generate_series(
Expand Down Expand Up @@ -292,7 +292,7 @@ impl AccessToken {
visit_count
), '{}') AS visits
FROM aggregated_visits
) as "visits_30_days: JsonValue"
) AS "visits_30_days: JsonValue"
"#,
access_token_id
)
Expand Down
10 changes: 5 additions & 5 deletions backend/src/models/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Category {
title,
family_id,
default_status,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
fill_color,
border_color,
version
Expand All @@ -66,7 +66,7 @@ impl Category {
title,
family_id,
default_status,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
fill_color,
border_color,
version
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Category {
title,
family_id,
default_status,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
fill_color,
border_color,
version
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Category {
title,
family_id,
default_status,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
fill_color,
border_color,
version
Expand All @@ -167,7 +167,7 @@ impl Category {
title,
family_id,
default_status,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
fill_color,
border_color,
version
Expand Down
10 changes: 5 additions & 5 deletions backend/src/models/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl AdminComment {
RETURNING *
)
SELECT i.id, i.entity_id, i.author, i.text, i.data, i.created_at, i.updated_at, i.moderated, i.version,
display_name as entity_display_name, category_id as entity_category_id
display_name AS entity_display_name, category_id AS entity_category_id
FROM inserted i
JOIN entities e
ON e.id = entity_id
Expand Down Expand Up @@ -195,7 +195,7 @@ impl AdminComment {
RETURNING *
)
SELECT i.id, i.entity_id, i.author, i.text, i.data, i.created_at, i.updated_at, i.moderated, i.version,
e.display_name as entity_display_name, e.category_id as entity_category_id
e.display_name AS entity_display_name, e.category_id AS entity_category_id
FROM inserted i
JOIN entities e
ON e.id = entity_id
Expand All @@ -218,7 +218,7 @@ impl AdminComment {
AdminComment,
r#"
SELECT c.id, c.entity_id, c.author, c.text, c.data, c.created_at, c.updated_at, c.moderated, c.version,
e.display_name as entity_display_name, e.category_id as entity_category_id
e.display_name AS entity_display_name, e.category_id AS entity_category_id
FROM comments c
JOIN entities e ON e.id = c.entity_id
WHERE c.id = $1
Expand Down Expand Up @@ -253,7 +253,7 @@ impl AdminComment {
AdminComment,
r#"
SELECT c.id, c.entity_id, c.author, c.text, c.data, c.created_at, c.updated_at, c.moderated, c.version,
e.display_name as entity_display_name, e.category_id as entity_category_id
e.display_name AS entity_display_name, e.category_id AS entity_category_id
FROM comments c
JOIN entities e ON e.id = c.entity_id
WHERE entity_id = $1
Expand All @@ -270,7 +270,7 @@ impl AdminComment {
sqlx::query_as!(
AdminListedComment,
r#"
SELECT c.id, c.entity_id, e.display_name as entity_display_name, e.category_id as entity_category_id, c.created_at,
SELECT c.id, c.entity_id, e.display_name AS entity_display_name, e.category_id AS entity_category_id, c.created_at,
c.author, c.moderated, c.updated_at
FROM comments c
INNER JOIN entities e ON c.entity_id = e.id
Expand Down
22 changes: 11 additions & 11 deletions backend/src/models/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ impl PublicEntity {
PublicEntity,
r#"
SELECT e.id, c.family_id, e.category_id, e.display_name, e.data, e.created_at, e.updated_at,
e.locations as "locations: Json<Vec<UnprocessedLocation>>",
e.locations AS "locations: Json<Vec<UnprocessedLocation>>",
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!",
f.entity_form as "entity_form: Json<Form>",
f.comment_form as "comment_form: Json<Form>"
) AS "tags!",
f.entity_form AS "entity_form: Json<Form>",
f.comment_form AS "comment_form: Json<Form>"
FROM entities e
INNER JOIN categories c ON e.category_id = c.id
INNER JOIN families f ON c.family_id = f.id
Expand Down Expand Up @@ -155,7 +155,7 @@ impl PublicEntity {
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
INNER JOIN entities_entities ee ON e.id = ee.child_id
WHERE ee.parent_id = $1 AND e.moderated AND NOT e.hidden
Expand All @@ -181,7 +181,7 @@ impl PublicEntity {
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
INNER JOIN entities_entities ee ON e.id = ee.parent_id
WHERE ee.child_id = $1 AND e.moderated AND NOT e.hidden
Expand Down Expand Up @@ -476,7 +476,7 @@ impl AdminEntity {
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
INNER JOIN entities_entities ee ON e.id = ee.parent_id
WHERE ee.child_id = $1
Expand All @@ -500,7 +500,7 @@ impl AdminEntity {
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
INNER JOIN entities_entities ee ON e.id = ee.child_id
WHERE ee.parent_id = $1
Expand All @@ -517,13 +517,13 @@ impl AdminEntity {
AdminEntity,
r#"
SELECT e.id, c.family_id, e.display_name, e.category_id,
e.locations as "locations: Json<Vec<UnprocessedLocation>>",
e.locations AS "locations: Json<Vec<UnprocessedLocation>>",
e.data, e.hidden, e.moderation_notes, e.moderated,
e.created_at, e.updated_at, e.version,
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
INNER JOIN categories c ON e.category_id = c.id
WHERE e.id = $1
Expand All @@ -544,7 +544,7 @@ impl AdminEntity {
COALESCE(
(SELECT array_agg(t.tag_id) FROM entity_tags t WHERE t.entity_id = e.id),
array[]::uuid[]
) as "tags!"
) AS "tags!"
FROM entities e
WHERE NOT e.moderated
ORDER BY created_at
Expand Down
56 changes: 28 additions & 28 deletions backend/src/models/entity_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ impl ViewerCachedEntity {
CachedClusteredEntity,
r#"
SELECT
id as "id!",
entity_id as "entity_id!",
category_id as "category_id!",
family_id as "family_id!",
display_name as "display_name!",
id AS "id!",
entity_id AS "entity_id!",
category_id AS "category_id!",
family_id AS "family_id!",
display_name AS "display_name!",
parent_id,
parent_display_name,
web_mercator_x as "web_mercator_x!",
web_mercator_y as "web_mercator_y!",
plain_text_location as "plain_text_location!",
web_mercator_x AS "web_mercator_x!",
web_mercator_y AS "web_mercator_y!",
plain_text_location AS "plain_text_location!",
cluster_id,
cluster_center_x,
cluster_center_y
Expand Down Expand Up @@ -383,16 +383,16 @@ impl ViewerCachedEntity {
PaginatedCachedEntity,
r#"
SELECT
id as "id!",
entity_id as "entity_id!",
category_id as "category_id!",
family_id as "family_id!",
display_name as "display_name!",
parents as "parents!: Json<Vec<ParentRepresentation>>",
locations as "locations!: Json<Vec<LocationRepresentation>>",
total_results as "total_results!",
total_pages as "total_pages!",
response_current_page as "response_current_page!"
id AS "id!",
entity_id AS "entity_id!",
category_id AS "category_id!",
family_id AS "family_id!",
display_name AS "display_name!",
parents AS "parents!: Json<Vec<ParentRepresentation>>",
locations AS "locations!: Json<Vec<LocationRepresentation>>",
total_results AS "total_results!",
total_pages AS "total_pages!",
response_current_page AS "response_current_page!"
FROM search_entities(
$1,
$2,
Expand Down Expand Up @@ -459,16 +459,16 @@ impl AdminCachedEntity {
AdminPaginatedCachedEntity,
r#"
SELECT
id as "id!",
entity_id as "entity_id!",
category_id as "category_id!",
tags_ids as "tags_ids!",
family_id as "family_id!",
display_name as "display_name!",
total_results as "total_results!",
total_pages as "total_pages!",
response_current_page as "response_current_page!",
hidden as "hidden!"
id AS "id!",
entity_id AS "entity_id!",
category_id AS "category_id!",
tags_ids AS "tags_ids!",
family_id AS "family_id!",
display_name AS "display_name!",
total_results AS "total_results!",
total_pages AS "total_pages!",
response_current_page AS "response_current_page!",
hidden AS "hidden!"
FROM search_entities_admin(
$1,
$2,
Expand Down
24 changes: 12 additions & 12 deletions backend/src/models/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ impl Family {
RETURNING
id,
title,
(SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
entity_form as "entity_form: Json<Form>",
comment_form as "comment_form: Json<Form>",
(SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
entity_form AS "entity_form: Json<Form>",
comment_form AS "comment_form: Json<Form>",
sort_order,
version
"#,
Expand Down Expand Up @@ -359,9 +359,9 @@ impl Family {
sqlx::query_as!(
Family,
r#"
SELECT id, title, (SELECT hash FROM icons WHERE id = icon_id) as icon_hash,
entity_form as "entity_form: Json<Form>",
comment_form as "comment_form: Json<Form>",
SELECT id, title, (SELECT hash FROM icons WHERE id = icon_id) AS icon_hash,
entity_form AS "entity_form: Json<Form>",
comment_form AS "comment_form: Json<Form>",
sort_order,
version
FROM families
Expand Down Expand Up @@ -403,9 +403,9 @@ impl Family {
sqlx::query_as!(
Family,
r#"
SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) as icon_hash,
families.entity_form as "entity_form: Json<Form>",
families.comment_form as "comment_form: Json<Form>",
SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) AS icon_hash,
families.entity_form AS "entity_form: Json<Form>",
families.comment_form AS "comment_form: Json<Form>",
families.sort_order,
families.version
FROM families
Expand All @@ -426,9 +426,9 @@ impl Family {
sqlx::query_as!(
Family,
r#"
SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) as icon_hash,
families.entity_form as "entity_form: Json<Form>",
families.comment_form as "comment_form: Json<Form>",
SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) AS icon_hash,
families.entity_form AS "entity_form: Json<Form>",
families.comment_form AS "comment_form: Json<Form>",
families.sort_order,
families.version
FROM families
Expand Down
Loading

0 comments on commit 25f8c34

Please sign in to comment.