diff --git a/backend/src/models/access_token.rs b/backend/src/models/access_token.rs index 46c3436..db0c8d4 100644 --- a/backend/src/models/access_token.rs +++ b/backend/src/models/access_token.rs @@ -99,9 +99,9 @@ impl AccessToken { id, title, token, - permissions as "permissions: Json", + permissions AS "permissions: Json", active, - 0 as "last_week_visits!" + 0 AS "last_week_visits!" "#, access_token.title, access_token.token, @@ -131,9 +131,9 @@ impl AccessToken { id, title, token, - permissions as "permissions: Json", + permissions AS "permissions: Json", 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, @@ -172,9 +172,9 @@ impl AccessToken { id, title, token, - permissions as "permissions: Json", + permissions AS "permissions: Json", active, - 0 as "last_week_visits!" + 0 AS "last_week_visits!" FROM access_tokens WHERE token = $1 "#, @@ -196,9 +196,9 @@ impl AccessToken { id, title, token, - permissions as "permissions: Json", + permissions AS "permissions: Json", 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 "#, @@ -217,9 +217,9 @@ impl AccessToken { id, title, token, - permissions as "permissions: Json", + permissions AS "permissions: Json", 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 "# ) @@ -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( @@ -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 ) diff --git a/backend/src/models/category.rs b/backend/src/models/category.rs index 9b6e90e..8436f34 100644 --- a/backend/src/models/category.rs +++ b/backend/src/models/category.rs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/backend/src/models/comment.rs b/backend/src/models/comment.rs index ead7651..06f03d7 100644 --- a/backend/src/models/comment.rs +++ b/backend/src/models/comment.rs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/backend/src/models/entity.rs b/backend/src/models/entity.rs index 5744978..f420cb5 100644 --- a/backend/src/models/entity.rs +++ b/backend/src/models/entity.rs @@ -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>", + e.locations AS "locations: Json>", 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
", - f.comment_form as "comment_form: Json" + ) AS "tags!", + f.entity_form AS "entity_form: Json", + f.comment_form AS "comment_form: Json" FROM entities e INNER JOIN categories c ON e.category_id = c.id INNER JOIN families f ON c.family_id = f.id @@ -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 @@ -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 @@ -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 @@ -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 @@ -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>", + e.locations AS "locations: Json>", 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 @@ -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 diff --git a/backend/src/models/entity_cache.rs b/backend/src/models/entity_cache.rs index 3963ec5..c252ac4 100644 --- a/backend/src/models/entity_cache.rs +++ b/backend/src/models/entity_cache.rs @@ -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 @@ -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>", - locations as "locations!: Json>", - 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>", + locations AS "locations!: Json>", + total_results AS "total_results!", + total_pages AS "total_pages!", + response_current_page AS "response_current_page!" FROM search_entities( $1, $2, @@ -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, diff --git a/backend/src/models/family.rs b/backend/src/models/family.rs index e355918..40a15b7 100644 --- a/backend/src/models/family.rs +++ b/backend/src/models/family.rs @@ -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", - comment_form as "comment_form: Json", + (SELECT hash FROM icons WHERE id = icon_id) AS icon_hash, + entity_form AS "entity_form: Json", + comment_form AS "comment_form: Json", sort_order, version "#, @@ -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", - comment_form as "comment_form: Json", + SELECT id, title, (SELECT hash FROM icons WHERE id = icon_id) AS icon_hash, + entity_form AS "entity_form: Json", + comment_form AS "comment_form: Json", sort_order, version FROM families @@ -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", - families.comment_form as "comment_form: Json", + SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) AS icon_hash, + families.entity_form AS "entity_form: Json", + families.comment_form AS "comment_form: Json", families.sort_order, families.version FROM families @@ -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", - families.comment_form as "comment_form: Json", + SELECT families.id, families.title, (SELECT hash FROM icons WHERE id = families.icon_id) AS icon_hash, + families.entity_form AS "entity_form: Json", + families.comment_form AS "comment_form: Json", families.sort_order, families.version FROM families diff --git a/backend/src/models/statistics.rs b/backend/src/models/statistics.rs index 0deb5aa..4dce54e 100644 --- a/backend/src/models/statistics.rs +++ b/backend/src/models/statistics.rs @@ -99,12 +99,12 @@ pub async fn home_page_stats(conn: &mut PgConnection) -> Result= NOW()::date - INTERVAL '30 days') as "total_visits_30_days!", - (SELECT COUNT(*) FROM access_tokens_visits WHERE visited_at >= NOW()::date - INTERVAL '7 days') as "total_visits_7_days!", + (SELECT COUNT(*) FROM entities WHERE moderated) AS "total_entities!", + (SELECT COUNT(*) FROM comments WHERE moderated) AS "total_comments!", + (SELECT COUNT(*) FROM entities WHERE NOT moderated) AS "pending_entities!", + (SELECT COUNT(*) FROM comments WHERE NOT moderated) AS "pending_comments!", + (SELECT COUNT(*) FROM access_tokens_visits WHERE visited_at >= NOW()::date - INTERVAL '30 days') AS "total_visits_30_days!", + (SELECT COUNT(*) FROM access_tokens_visits WHERE visited_at >= NOW()::date - INTERVAL '7 days') AS "total_visits_7_days!", ( WITH date_series AS ( SELECT generate_series( @@ -136,7 +136,7 @@ pub async fn home_page_stats(conn: &mut PgConnection) -> Result