new functions

This commit is contained in:
Mateusz Gruszczyński
2026-07-29 09:49:37 +02:00
parent bbcd1fe987
commit 904f59146b
23 changed files with 469 additions and 53 deletions
+6
View File
@@ -21,6 +21,9 @@ pub enum Query {
RESOURCE_COLOR_BY_USER,
RESOURCE_COLOR_DELETE,
RESOURCE_COLOR_INSERT,
RESOURCE_EDITOR_SETTINGS_SELECT,
RESOURCE_EDITOR_SETTINGS_DELETE,
RESOURCE_EDITOR_SETTINGS_INSERT,
AUTH_ACCOUNT_ACTION_BY_TOKEN,
AUTH_CONSUME_ACCOUNT_ACTION,
AUTH_UPDATE_EMAIL,
@@ -160,6 +163,9 @@ pub const AUTH_EDITOR_COLOR_BY_USER: Query = Query::AUTH_EDITOR_COLOR_BY_USER;
pub const RESOURCE_COLOR_BY_USER: Query = Query::RESOURCE_COLOR_BY_USER;
pub const RESOURCE_COLOR_DELETE: Query = Query::RESOURCE_COLOR_DELETE;
pub const RESOURCE_COLOR_INSERT: Query = Query::RESOURCE_COLOR_INSERT;
pub const RESOURCE_EDITOR_SETTINGS_SELECT: Query = Query::RESOURCE_EDITOR_SETTINGS_SELECT;
pub const RESOURCE_EDITOR_SETTINGS_DELETE: Query = Query::RESOURCE_EDITOR_SETTINGS_DELETE;
pub const RESOURCE_EDITOR_SETTINGS_INSERT: Query = Query::RESOURCE_EDITOR_SETTINGS_INSERT;
pub const AUTH_ACCOUNT_ACTION_BY_TOKEN: Query = Query::AUTH_ACCOUNT_ACTION_BY_TOKEN;
pub const AUTH_CONSUME_ACCOUNT_ACTION: Query = Query::AUTH_CONSUME_ACCOUNT_ACTION;
pub const AUTH_UPDATE_EMAIL: Query = Query::AUTH_UPDATE_EMAIL;
+3
View File
@@ -15,6 +15,9 @@ pub fn get(query: Query) -> &'static str {
Query::AUTH_EDITOR_COLOR_BY_USER => r#"SELECT editor_color FROM users WHERE id = ?"#,
Query::RESOURCE_COLOR_BY_USER => r#"SELECT color FROM user_resource_colors WHERE user_id = ? AND resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_COLOR_DELETE => r#"DELETE FROM user_resource_colors WHERE user_id = ? AND resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_SELECT => r#"SELECT authorship_mode, CASE WHEN colors_enabled THEN 1 ELSE 0 END FROM resource_editor_settings WHERE resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_DELETE => r#"DELETE FROM resource_editor_settings WHERE resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_INSERT => r#"INSERT INTO resource_editor_settings (resource_kind, resource_slug, authorship_mode, colors_enabled) VALUES (?, ?, ?, ?)"#,
Query::RESOURCE_COLOR_INSERT => r#"INSERT INTO user_resource_colors (user_id, resource_kind, resource_slug, color) VALUES (?, ?, ?, ?)"#,
Query::AUTH_ACCOUNT_ACTION_BY_TOKEN => r#"SELECT user_id, action, CAST(payload AS CHAR CHARACTER SET utf8mb4) AS payload, expires_at, used_at FROM account_action_tokens WHERE token = ?"#,
Query::AUTH_CONSUME_ACCOUNT_ACTION => r#"UPDATE account_action_tokens SET used_at = ? WHERE token = ? AND used_at IS NULL"#,
+3
View File
@@ -15,6 +15,9 @@ pub fn get(query: Query) -> &'static str {
Query::AUTH_EDITOR_COLOR_BY_USER => r#"SELECT editor_color FROM users WHERE id = $1"#,
Query::RESOURCE_COLOR_BY_USER => r#"SELECT color FROM user_resource_colors WHERE user_id = $1 AND resource_kind = $2 AND resource_slug = $3"#,
Query::RESOURCE_COLOR_DELETE => r#"DELETE FROM user_resource_colors WHERE user_id = $1 AND resource_kind = $2 AND resource_slug = $3"#,
Query::RESOURCE_EDITOR_SETTINGS_SELECT => r#"SELECT authorship_mode, (CASE WHEN colors_enabled THEN 1 ELSE 0 END)::BIGINT FROM resource_editor_settings WHERE resource_kind = $1 AND resource_slug = $2"#,
Query::RESOURCE_EDITOR_SETTINGS_DELETE => r#"DELETE FROM resource_editor_settings WHERE resource_kind = $1 AND resource_slug = $2"#,
Query::RESOURCE_EDITOR_SETTINGS_INSERT => r#"INSERT INTO resource_editor_settings (resource_kind, resource_slug, authorship_mode, colors_enabled) VALUES ($1, $2, $3, $4)"#,
Query::RESOURCE_COLOR_INSERT => r#"INSERT INTO user_resource_colors (user_id, resource_kind, resource_slug, color) VALUES ($1, $2, $3, $4)"#,
Query::AUTH_ACCOUNT_ACTION_BY_TOKEN => r#"SELECT user_id, action, payload, expires_at, used_at FROM account_action_tokens WHERE token = $1"#,
Query::AUTH_CONSUME_ACCOUNT_ACTION => r#"UPDATE account_action_tokens SET used_at = $1 WHERE token = $2 AND used_at IS NULL"#,
+3
View File
@@ -15,6 +15,9 @@ pub fn get(query: Query) -> &'static str {
Query::AUTH_EDITOR_COLOR_BY_USER => r#"SELECT editor_color FROM users WHERE id = ?"#,
Query::RESOURCE_COLOR_BY_USER => r#"SELECT color FROM user_resource_colors WHERE user_id = ? AND resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_COLOR_DELETE => r#"DELETE FROM user_resource_colors WHERE user_id = ? AND resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_SELECT => r#"SELECT authorship_mode, CASE WHEN colors_enabled THEN 1 ELSE 0 END FROM resource_editor_settings WHERE resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_DELETE => r#"DELETE FROM resource_editor_settings WHERE resource_kind = ? AND resource_slug = ?"#,
Query::RESOURCE_EDITOR_SETTINGS_INSERT => r#"INSERT INTO resource_editor_settings (resource_kind, resource_slug, authorship_mode, colors_enabled) VALUES (?, ?, ?, ?)"#,
Query::RESOURCE_COLOR_INSERT => r#"INSERT INTO user_resource_colors (user_id, resource_kind, resource_slug, color) VALUES (?, ?, ?, ?)"#,
Query::AUTH_ACCOUNT_ACTION_BY_TOKEN => r#"SELECT user_id, action, payload, expires_at, used_at FROM account_action_tokens WHERE token = ?"#,
Query::AUTH_CONSUME_ACCOUNT_ACTION => r#"UPDATE account_action_tokens SET used_at = ? WHERE token = ? AND used_at IS NULL"#,