Routines
| Name | Type | Language | Deterministic | Return Type | Security Restriction | Comments |
|---|---|---|---|---|---|---|
| unban_user_globally(p_user_id integer) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Removes the global ban from a user, clearing the ban reason and expiration timestamp. |
| count_chat_messages(p_stream_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the number of non-deleted chat messages in a given stream. |
| update_stream_details(p_stream_id integer, p_title text DEFAULT NULL::text, p_desc text DEFAULT NULL::text, p_thumbnail text DEFAULT NULL::text) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Updates stream metadata including title, description, and thumbnail. NULL values are not updated. |
| citext_pattern_le(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| rotate_and_return_raw_token(p_old_token_hash text, p_new_expires_at timestamp without time zone) | FUNCTION | plpgsql | false | text | INVOKER | Rotates a refresh token, generates a new raw token and returns it for client use (optional implementation). |
| fips_mode() | FUNCTION | c | false | boolean | INVOKER | |
| get_latest_statistic_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | TABLE(statistic_in_time_id integer, stream_id integer, stream_statistic_type_id integer, statistic_type_name text, statistic_type_description text, value integer, timepoint timestamp without time zone) | INVOKER | Retrieves the latest statistic entry for a specific stream and statistic type. |
| delete_role_by_name(p_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a role by name if no permissions are assigned to it. Returns TRUE on success, FALSE if permissions are assigned. |
| is_token_hash_unique(p_token_hash text) | FUNCTION | plpgsql | false | boolean | INVOKER | Validates that a token hash is unique before inserting (optional - unique index already exists) |
| get_user_token_history(p_user_id integer, p_limit integer DEFAULT 100) | FUNCTION | plpgsql | false | SETOF refresh_tokens | INVOKER | Retrieves the token history for a user with optional limit, sorted by most recent first. |
| pgp_sym_decrypt_bytea(bytea, text, text) | FUNCTION | c | true | bytea | INVOKER | |
| get_permission_by_name(p_name text) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves a permission by its name. |
| get_subscription_count_by_user(p_user_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the number of streamers a user is subscribed to. |
| get_average_statistic_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | numeric | INVOKER | Returns the average value of a statistic for the given stream and type. If the stream ended, averages only values until the ended_at. |
| pgp_sym_encrypt(text, text) | FUNCTION | c | false | bytea | INVOKER | |
| add_path_to_stream(p_stream_id integer, p_path text) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Associates a file path (e.g., media storage path) with a stream. |
| get_permissions_by_role_id(p_role_id integer) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves all permissions assigned to a role by role ID. |
| get_sum_statistic_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | bigint | INVOKER | Calculates the sum of statistic values for a specific stream and type. If the stream has ended, the sum includes only values up to ended_at. |
| get_message_edit_history(p_message_id integer) | FUNCTION | plpgsql | false | SETOF chat_message_edit_histories | INVOKER | Returns the edit history for a given chat message, sorted by most recent first. |
| set_stream_live_status(p_stream_id integer, p_is_live boolean) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Sets the live status of a stream. |
| update_stream_token(p_user_id integer, p_stream_token text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the stream token for a user to the specified value. |
| create_user(p_username citext, p_email citext, p_password text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Creates a new user account if username and email do not already exist. Returns the newly created or existing user. |
| assign_role_to_user_in_context_by_role_id(p_user_id integer, p_role_id integer, p_context_id integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Assigns a role to a user within a specific context (e.g., streamer moderator). Returns TRUE if assignment was successful. |
| get_subscriptions_by_user(p_user_id integer) | FUNCTION | plpgsql | false | TABLE(user_id integer, username citext, subscribed_since timestamp without time zone) | INVOKER | Retrieves all streamers that a user is subscribed to with subscription timestamps. |
| texticlike(citext, citext) | FUNCTION | internal | true | boolean | INVOKER | |
| citext(boolean) | FUNCTION | internal | true | citext | INVOKER | |
| assign_role_to_user_by_role_name(p_user_id integer, p_role_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Assigns a role (by name) to a user globally. Returns TRUE if successful, FALSE if role not found. |
| get_statistic_type_by_name(p_name text) | FUNCTION | plpgsql | false | stream_statistics_types | INVOKER | Retrieves a stream statistic type by its exact name. |
| pgp_pub_encrypt_bytea(bytea, bytea) | FUNCTION | c | false | bytea | INVOKER | |
| get_all_roles() | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Retrieves all roles from the system. |
| get_top_streamers_by_subscribers(p_limit integer DEFAULT 10) | FUNCTION | plpgsql | false | TABLE(streamer_id integer, username citext, subscriber_count integer) | INVOKER | Retrieves the top streamers ranked by subscriber count, useful for discovery features. |
| get_all_messages_paginated(p_stream_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Returns all chat messages in a stream, including deleted ones, paginated. |
| count_statistics_for_stream(p_stream_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the total number of statistic entries for a specific stream. |
| touch_session_last_used(p_session_id text) | FUNCTION | plpgsql | false | SETOF sessions | INVOKER | Updates the last_used_at timestamp of a session to track user activity. |
| get_statistics_for_stream_by_date_range(p_stream_id integer, p_start_date timestamp without time zone, p_end_date timestamp without time zone, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT 0) | FUNCTION | plpgsql | false | TABLE(statistic_in_time_id integer, stream_id integer, stream_statistic_type_id integer, statistic_type_name text, statistic_type_description text, value integer, timepoint timestamp without time zone) | INVOKER | Retrieves statistic entries for a specific stream within a date range, including type name and description, ordered by timepoint descending. Supports pagination with limit and offset parameters. |
| revoke_role_from_user_by_role_id(p_user_id integer, p_role_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a role from a user globally. Returns TRUE on success, FALSE if role assignment not found. |
| encrypt(bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| pgp_sym_encrypt_bytea(bytea, text, text) | FUNCTION | c | false | bytea | INVOKER | |
| user_has_permission_by_permission_name_in_context(p_user_id integer, p_permission_name text, p_context_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user has a specific permission (by name) within a given context through their assigned roles. |
| pgp_sym_decrypt(bytea, text) | FUNCTION | c | true | text | INVOKER | |
| get_permission_by_id(p_permission_id integer) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves a permission by its ID. |
| min(citext) | AGGREGATE | internal | true | citext | INVOKER | |
| pgp_pub_encrypt(text, bytea) | FUNCTION | c | false | bytea | INVOKER | |
| update_user_profile_banner(p_user_id integer, p_profile_banner text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the profile banner image URL for a user. |
| pgp_key_id(bytea) | FUNCTION | c | true | text | INVOKER | |
| cleanup_expired_sessions_tokens() | FUNCTION | plpgsql | false | boolean | INVOKER | Cleanup function that marks expired sessions and tokens as inactive/revoked for database maintenance. |
| get_permissions_by_role_name(p_name text) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves all permissions assigned to a role by role name. |
| citext_pattern_gt(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| strpos(citext, citext) | FUNCTION | sql | true | integer | INVOKER | |
| pgp_pub_decrypt(bytea, bytea) | FUNCTION | c | true | text | INVOKER | |
| subscription_exists(p_user_id integer, p_streamer_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a subscription relationship already exists between a user and a streamer. |
| citext_larger(citext, citext) | FUNCTION | c | true | citext | INVOKER | |
| pgp_armor_headers(text, OUT key text, OUT value text) | FUNCTION | c | true | SETOF record | INVOKER | |
| mark_refresh_token_used(p_token_hash text) | FUNCTION | plpgsql | false | boolean | INVOKER | Marks a refresh token as used by updating its used_at timestamp for audit purposes. |
| citext_pattern_ge(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| delete_old_statistics_for_stream(p_stream_id integer, p_before_date timestamp without time zone) | FUNCTION | plpgsql | false | integer | INVOKER | Deletes statistic entries for a specific stream older than the specified date. Returns the number of deleted records. |
| user_has_permission_by_permission_id_in_context(p_user_id integer, p_permission_id integer, p_context_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user has a specific permission (by ID) within a given context through their assigned roles. |
| delete_statistics_for_type(p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Deletes all statistic entries for a specific statistic type across all streams. Returns the number of deleted entries. |
| create_stream(p_streamer_id integer, p_title text DEFAULT NULL::text, p_desc text DEFAULT NULL::text) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Creates a new live stream for a streamer. Raises exception if user is not a streamer or already has active stream. |
| check_if_message_exists(p_message_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a chat message with the given ID exists. |
| pgp_pub_decrypt_bytea(bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| get_subscribers_paginated(p_streamer_id integer, p_offset integer DEFAULT 0, p_limit integer DEFAULT 10) | FUNCTION | plpgsql | false | TABLE(user_id integer, username citext, subscribed_since timestamp without time zone) | INVOKER | Retrieves subscribers for a streamer with pagination, sorted by subscription date. |
| citext_pattern_cmp(citext, citext) | FUNCTION | c | true | integer | INVOKER | |
| get_recent_subscriptions_by_user(p_user_id integer, p_limit integer DEFAULT 5) | FUNCTION | plpgsql | false | TABLE(streamer_id integer, username citext, subscribed_since timestamp without time zone) | INVOKER | Retrieves the most recent subscriptions for a user with optional limit. |
| regexp_split_to_array(string citext, pattern citext, flags text) | FUNCTION | sql | true | text[] | INVOKER | |
| regexp_matches(string citext, pattern citext, flags text) | FUNCTION | sql | true | SETOF text[] | INVOKER | |
| get_message_edit_history_paginated(p_message_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | SETOF chat_message_edit_histories | INVOKER | Returns the edit history for a chat message, paginated with optional LIMIT and OFFSET. |
| update_statistic_type(p_stream_statistic_type_id integer, p_name text, p_description text DEFAULT NULL::text) | FUNCTION | plpgsql | false | stream_statistics_types | INVOKER | Updates an existing stream statistic type by ID. Returns the updated statistic type. Raises an exception if the type does not exist. |
| update_user_avatar(p_user_id integer, p_avatar text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the avatar image URL for a user. |
| citext_eq(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| count_statistic_types() | FUNCTION | plpgsql | false | integer | INVOKER | Returns the total number of stream statistic types. |
| user_has_permission_by_permission_id(p_user_id integer, p_permission_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user has a specific permission (by ID) through their assigned roles. |
| check_if_user_exists(p_user_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user with the specified user ID exists in the database. |
| update_user_username(p_user_id integer, p_username citext) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the username of a user. |
| get_top_streams_by_statistic_type(p_stream_statistic_type_id integer, p_limit integer DEFAULT 10, p_start_date timestamp without time zone DEFAULT NULL::timestamp without time zone, p_end_date timestamp without time zone DEFAULT NULL::timestamp without time zone) | FUNCTION | plpgsql | false | TABLE(stream_id integer, total_value bigint, avg_value numeric, max_value integer, count_entries integer) | INVOKER | Returns the top streams ranked by total statistic value for a specific type, optionally within a date range. |
| decrypt(bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| update_user_email(p_user_id integer, p_email citext) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the email address of a user. |
| regexp_match(string citext, pattern citext) | FUNCTION | sql | true | text[] | INVOKER | |
| is_user_message_author(p_message_id integer, p_user_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if the specified user is the author of the given chat message. |
| delete_statistics_for_stream(p_stream_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Deletes all statistic entries for a specific stream. Returns the number of deleted entries. |
| citext_ge(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| pgp_pub_decrypt_bytea(bytea, bytea, text, text) | FUNCTION | c | true | bytea | INVOKER | |
| rotate_refresh_token(p_old_token_hash text, p_new_expires_at timestamp without time zone, p_new_raw_token text) | FUNCTION | plpgsql | false | refresh_tokens | INVOKER | Atomically rotates a refresh token by marking old token as replaced and creating a new one. Ensures race condition safety. |
| get_roles_by_user_in_context(p_user_id integer, p_context_id integer) | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Retrieves all roles assigned to a user within a specific context. |
| check_if_user_is_streaming(p_streamer_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user currently has an active live stream. |
| delete_old_statistics(p_before_date timestamp without time zone) | FUNCTION | plpgsql | false | integer | INVOKER | Deletes all statistic entries older than the specified date. Returns the number of deleted records. |
| digest(bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| regexp_replace(string citext, pattern citext, replacement text, flags text) | FUNCTION | sql | true | text | INVOKER | |
| crypt(text, text) | FUNCTION | c | true | text | INVOKER | |
| regexp_split_to_array(string citext, pattern citext) | FUNCTION | sql | true | text[] | INVOKER | |
| assign_role_to_user_in_context_by_role_name(p_user_id integer, p_role_name text, p_context_id integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | boolean | INVOKER | |
| delete_statistic_type(p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a stream statistic type by ID. This will also cascade delete all related stream statistics. Returns TRUE if the deletion was successful, FALSE otherwise. |
| get_statistic_type_by_id(p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | SETOF stream_statistics_types | INVOKER | Retrieves a specific stream statistic type by ID. |
| ban_user_in_chat(p_streamer_id integer, p_user_id integer, p_banner_id integer, p_reason text DEFAULT 'Unknown reason'::text, p_is_permanent boolean DEFAULT false, p_ban_end_date timestamp without time zone DEFAULT NULL::timestamp without time zone) | FUNCTION | plpgsql | false | SETOF banned_users_per_streamer | INVOKER | Bans a user from a streamer chat. Ban can be permanent or temporary with optional expiration date. |
| check_if_user_is_streaming_and_public(p_streamer_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user currently has an active public stream. |
| get_deleted_messages_paginated(p_stream_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Returns deleted chat messages in a stream, paginated with optional LIMIT and OFFSET. |
| revoke_all_user_sessions(p_user_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes all sessions and tokens for a specific user, effectively logging them out everywhere. |
| citextin(cstring) | FUNCTION | internal | true | citext | INVOKER | |
| pgp_pub_encrypt_bytea(bytea, bytea, text) | FUNCTION | c | false | bytea | INVOKER | |
| citext_gt(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| gen_salt(text) | FUNCTION | c | false | text | INVOKER | |
| hard_delete_user(IN p_user_id integer) | PROCEDURE | plpgsql | false | INVOKER | Permanently deletes a user and all associated data from the system. |
|
| extend_session_expiry(p_session_id text, p_new_expires_at timestamp without time zone) | FUNCTION | plpgsql | false | SETOF sessions | INVOKER | Extends the expiration time of an existing session. |
| pgp_pub_decrypt(bytea, bytea, text, text) | FUNCTION | c | true | text | INVOKER | |
| citextout(citext) | FUNCTION | internal | true | cstring | INVOKER | |
| create_session(p_user_id integer, p_expires_at timestamp without time zone, p_ip_address text DEFAULT NULL::text, p_user_agent text DEFAULT NULL::text, p_device_info text DEFAULT NULL::text) | FUNCTION | plpgsql | false | SETOF sessions | INVOKER | Creates a new user session with device information and expiration time. Returns the created session record. |
| get_statistics_summary() | FUNCTION | plpgsql | false | TABLE(total_statistic_types integer, total_statistic_entries bigint, oldest_entry_date timestamp without time zone, newest_entry_date timestamp without time zone, total_streams_with_statistics integer) | INVOKER | Returns a summary of all statistics in the database including counts, date ranges, and streams with statistics. |
| set_stream_lock_status(p_stream_id integer, p_is_locked boolean) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Sets the lock status of a stream (locks prevent new interactions) |
| hmac(text, text, text) | FUNCTION | c | true | bytea | INVOKER | |
| get_role_by_name(p_role_name text) | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Retrieves a role by its name. |
| get_deleted_messages(p_stream_id integer) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Returns all deleted chat messages in a given stream. |
| undelete_chat_message(p_message_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Restores a previously deleted chat message. |
| citext_pattern_lt(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| undelete_all_chat_messages(p_stream_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Restores all deleted chat messages in a given stream and returns the count of restored messages. |
| delete_permission_by_name(p_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a permission by name. Returns TRUE on success, FALSE if permission not found. |
| split_part(citext, citext, integer) | FUNCTION | sql | true | text | INVOKER | |
| pgp_sym_encrypt_bytea(bytea, text) | FUNCTION | c | false | bytea | INVOKER | |
| decrypt_iv(bytea, bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| end_stream(p_stream_id integer) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Ends a live stream by marking it as not live and setting the end timestamp. |
| statistic_type_exists_by_name(p_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a stream statistic type with the given name exists. Returns TRUE if exists, FALSE otherwise. |
| update_user_password(p_user_id integer, p_password text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the password hash for a user. |
| remove_subscription(p_user_id integer, p_streamer_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Removes a subscription between a user and streamer. Returns TRUE if subscription was deleted, FALSE if it did not exist. |
| ban_user_globally(p_user_id integer, p_reason text DEFAULT 'Unknown reason'::text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Globally bans a user with a specified reason. The user is marked as banned in the system. |
| get_all_permissions() | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves all permissions from the system. |
| get_statistics_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT 0) | FUNCTION | plpgsql | false | TABLE(statistic_in_time_id integer, stream_id integer, stream_statistic_type_id integer, statistic_type_name text, statistic_type_description text, value integer, timepoint timestamp without time zone) | INVOKER | Retrieves statistic entries for a specific stream and statistic type, including type name and description, ordered by timepoint descending. Supports pagination with limit and offset. |
| texticlike(citext, text) | FUNCTION | internal | true | boolean | INVOKER | |
| hmac(bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| cleanup_revoked_tokens_older_than(p_days integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Permanently deletes revoked tokens older than the specified number of days (database pruning/maintenance). |
| get_hourly_statistics_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer, p_start_date timestamp without time zone, p_end_date timestamp without time zone) | FUNCTION | plpgsql | false | TABLE(hour_timestamp timestamp without time zone, avg_value numeric, min_value integer, max_value integer, count_entries integer) | INVOKER | Returns hourly aggregated statistics (avg, min, max, count) for a stream and type within a date range. |
| citextsend(citext) | FUNCTION | internal | false | bytea | INVOKER | |
| generate_access_token(length integer DEFAULT 16) | FUNCTION | plpgsql | false | text | INVOKER | Generates a random access token of specified length using hexadecimal encoding. Minimum length is 8 characters. |
| end_all_streams() | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Ends all active streams in the system. |
| end_all_streams_for_user(p_user_id integer) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Ends all active streams for a specific user/streamer. |
| get_user_messages_paginated(p_stream_id integer, p_user_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Returns all non-deleted chat messages from a specific user in a stream, paginated. |
| get_role_by_id(p_role_id integer) | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Retrieves a role by its ID. |
| get_subscriptions_paginated(p_user_id integer, p_offset integer DEFAULT 0, p_limit integer DEFAULT 10) | FUNCTION | plpgsql | false | TABLE(streamer_id integer, username citext, subscribed_since timestamp without time zone) | INVOKER | Retrieves subscriptions for a user with pagination, sorted by subscription date. |
| get_refresh_tokens_by_session(p_session_id text) | FUNCTION | plpgsql | false | SETOF refresh_tokens | INVOKER | Retrieves all refresh tokens associated with a specific session. |
| delete_permission_by_id(p_permission_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a permission by ID. Returns TRUE on success, FALSE if permission not found. |
| check_if_user_is_streamer(p_user_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user is a streamer by verifying they have a non-empty stream token. |
| pgp_pub_decrypt(bytea, bytea, text) | FUNCTION | c | true | text | INVOKER | |
| get_roles_by_user(p_user_id integer) | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Retrieves all global roles assigned to a user (without context). |
| generate_token_hash(p_raw_token text) | FUNCTION | plpgsql | false | text | INVOKER | Generates a SHA256 hash of a raw token with optional pepper for secure token storage. |
| dearmor(text) | FUNCTION | c | true | bytea | INVOKER | |
| get_subscribers_by_streamer(p_streamer_id integer) | FUNCTION | plpgsql | false | TABLE(user_id integer, username citext, subscribed_since timestamp without time zone) | INVOKER | Retrieves all users subscribed to a streamer with subscription timestamps. |
| update_stream_statistic_value(p_statistic_in_time_id integer, p_value integer) | FUNCTION | plpgsql | false | stream_statistics_in_time | INVOKER | Updates an existing stream statistic entry by ID. Returns the updated statistic entry. Raises an exception if the entry does not exist. |
| get_active_streams() | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Retrieves all currently active and public streams. |
| citext_hash_extended(citext, bigint) | FUNCTION | c | true | bigint | INVOKER | |
| texticnlike(citext, text) | FUNCTION | internal | true | boolean | INVOKER | |
| texticregexeq(citext, text) | FUNCTION | internal | true | boolean | INVOKER | |
| get_active_sessions(p_user_id integer) | FUNCTION | plpgsql | false | SETOF sessions | INVOKER | Retrieves all active and non-expired sessions for a user. |
| get_max_statistic_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the maximum value for the requested statistic type. If the stream ended, it only considers values up to ended_at. |
| regexp_split_to_table(string citext, pattern citext, flags text) | FUNCTION | sql | true | SETOF text | INVOKER | |
| get_streams_by_user_id(p_user_id integer) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Retrieves all streams (active and inactive) for a specific user/streamer. |
| get_refresh_token(p_token_hash text) | FUNCTION | plpgsql | false | refresh_tokens | INVOKER | Retrieves a refresh token record by its hash. |
| remove_all_subscribers_by_streamer(p_streamer_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Removes all subscribers from a streamer and returns count of deleted subscriptions. |
| pgp_pub_decrypt_bytea(bytea, bytea) | FUNCTION | c | true | bytea | INVOKER | |
| pgp_sym_decrypt_bytea(bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| get_stream_by_id(p_stream_id integer) | FUNCTION | plpgsql | false | SETOF streams | INVOKER | Retrieves a stream by its ID. |
| revoke_tokens_by_session(p_session_id text) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes all refresh tokens associated with a specific session. |
| get_user_by_email(p_email citext) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Retrieves a user by their email address. |
| revoke_role_from_user_in_context_by_role_name(p_user_id integer, p_role_name text, p_context_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a role (by name) from a user within a specific context. Returns TRUE on success, FALSE if role not found or assignment does not exist. |
| issue_refresh_token(p_session_id text, p_user_id integer, p_expires_at timestamp without time zone, p_raw_token text) | FUNCTION | plpgsql | false | refresh_tokens | INVOKER | Issues a new refresh token for a session by hashing the raw token and storing the hash in the database. |
| citext_smaller(citext, citext) | FUNCTION | c | true | citext | INVOKER | |
| texticnlike(citext, citext) | FUNCTION | internal | true | boolean | INVOKER | |
| get_permissions_by_user(p_user_id integer) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Retrieves all global permissions granted to a user through their assigned roles. |
| create_chat_message(p_stream_id integer, p_user_id integer, p_content text) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Creates a new chat message in a stream and returns the created message. |
| armor(bytea) | FUNCTION | c | true | text | INVOKER | |
| user_has_permission_in_context(p_user_id integer, p_permission_name text, p_context_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user has a specific permission within a given context. |
| get_subscription_count_by_streamer(p_streamer_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the number of subscribers for a streamer. |
| create_role(p_name text) | FUNCTION | plpgsql | false | SETOF roles | INVOKER | Creates a new role if it does not already exist. Returns the existing or newly created role. |
| get_user_by_id(p_id integer) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Retrieves a user by their user ID. |
| citextrecv(internal) | FUNCTION | internal | false | citext | INVOKER | |
| get_subscription_details(p_user_id integer, p_streamer_id integer) | FUNCTION | plpgsql | false | TABLE(user_id integer, streamer_id integer, subscribed_since timestamp without time zone, streamer_username citext, user_username citext) | INVOKER | Retrieves detailed subscription information including both usernames for a specific user-streamer relationship. |
| replace(citext, citext, citext) | FUNCTION | sql | true | text | INVOKER | |
| regexp_split_to_table(string citext, pattern citext) | FUNCTION | sql | true | SETOF text | INVOKER | |
| assign_permission_to_role(p_role_id integer, p_permission_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Assigns a permission to a role. Returns TRUE if assignment was successful or already exists. |
| get_chat_messages(p_stream_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT NULL::integer) | FUNCTION | plpgsql | false | SETOF chat_messages | INVOKER | Returns paginated chat messages for a given stream, excluding deleted messages. |
| add_stream_statistic(p_stream_id integer, p_stream_statistic_type_id integer, p_value integer, p_timepoint timestamp without time zone DEFAULT CURRENT_TIMESTAMP) | FUNCTION | plpgsql | false | stream_statistics_in_time | INVOKER | Adds a new stream statistic entry for the specified stream and statistic type. Returns the newly created statistic entry. |
| revoke_role_from_user_in_context_by_role_id(p_user_id integer, p_role_id integer, p_context_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a role from a user within a specific context. Returns TRUE on success, FALSE if role assignment not found. |
| add_subscription(p_user_id integer, p_streamer_id integer) | FUNCTION | plpgsql | false | SETOF subscribers | INVOKER | Adds a subscription from a user to a streamer. Returns existing subscription if already subscribed, otherwise creates new subscription. |
| get_statistics_for_stream(p_stream_id integer, p_limit integer DEFAULT NULL::integer, p_offset integer DEFAULT 0) | FUNCTION | plpgsql | false | TABLE(statistic_in_time_id integer, stream_id integer, stream_statistic_type_id integer, statistic_type_name text, statistic_type_description text, value integer, timepoint timestamp without time zone) | INVOKER | Retrieves all statistic entries for a specific stream, including type name and description, ordered by timepoint descending. Supports pagination with limit and offset parameters. |
| statistic_type_exists_by_id(p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a stream statistic type with the given ID exists. Returns TRUE if exists, FALSE otherwise. |
| regexp_matches(string citext, pattern citext) | FUNCTION | sql | true | SETOF text[] | INVOKER | |
| armor(bytea, text[], text[]) | FUNCTION | c | true | text | INVOKER | |
| get_daily_statistics_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer, p_start_date timestamp without time zone, p_end_date timestamp without time zone) | FUNCTION | plpgsql | false | TABLE(day_date date, avg_value numeric, min_value integer, max_value integer, count_entries integer) | INVOKER | Returns daily aggregated statistics (avg, min, max, count) for a stream and type within a date range. |
| user_has_permission(p_user_id integer, p_permission_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Checks if a user has a specific global permission through their assigned roles. |
| get_sessions_with_refresh_tokens(p_user_id integer) | FUNCTION | plpgsql | false | TABLE(session_id text, last_token_issued_at timestamp without time zone) | INVOKER | Retrieves all sessions with their last token issuance timestamp, useful for session management UI. |
| pgp_sym_decrypt(bytea, text, text) | FUNCTION | c | true | text | INVOKER | |
| get_all_statistic_types() | FUNCTION | plpgsql | false | SETOF stream_statistics_types | INVOKER | Retrieves all stream statistic types ordered by name. |
| citext_ne(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| max(citext) | AGGREGATE | internal | true | citext | INVOKER | |
| encrypt_iv(bytea, bytea, bytea, text) | FUNCTION | c | true | bytea | INVOKER | |
| revoke_session(p_session_id text) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a session and all its associated refresh tokens. |
| get_min_statistic_for_stream_and_type(p_stream_id integer, p_stream_statistic_type_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Gets the minimum statistic value for a specific stream and type. If the stream has ended, the result includes only values up to ended_at. |
| pgp_sym_encrypt(text, text, text) | FUNCTION | c | false | bytea | INVOKER | |
| revoke_permission_from_role(p_role_id integer, p_permission_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a permission from a role. Returns TRUE on success, FALSE if permission assignment not found. |
| replace_refresh_token(p_old_token_hash text, p_new_token_id text) | FUNCTION | plpgsql | false | SETOF refresh_tokens | INVOKER | Updates replaced_by_id field of an old token to link it to a new token during token rotation. |
| citext_le(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| is_refresh_token_valid(p_token_hash text) | FUNCTION | plpgsql | false | boolean | INVOKER | Validates a refresh token by checking if it is active, not revoked, not expired, not replaced, and its session is valid. |
| citext_lt(citext, citext) | FUNCTION | c | true | boolean | INVOKER | |
| hard_delete_chat_message(p_message_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Permanently deletes a chat message from the database and returns TRUE if a row was deleted, FALSE otherwise. |
| regexp_match(string citext, pattern citext, flags text) | FUNCTION | sql | true | text[] | INVOKER | |
| regexp_replace(string citext, pattern citext, replacement text) | FUNCTION | sql | true | text | INVOKER | |
| revoke_role_from_user_by_role_name(p_user_id integer, p_role_name text) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a role (by name) from a user globally. Returns TRUE on success, FALSE if role not found or assignment does not exist. |
| delete_stream_statistic(p_statistic_in_time_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a specific stream statistic entry by ID. Returns TRUE if the deletion was successful, FALSE otherwise. |
| gen_random_uuid() | FUNCTION | c | false | uuid | INVOKER | |
| texticregexne(citext, text) | FUNCTION | internal | true | boolean | INVOKER | |
| remove_all_subscriptions_by_user(p_user_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Removes all subscriptions from a user and returns count of deleted subscriptions. |
| pgp_pub_encrypt(text, bytea, text) | FUNCTION | c | false | bytea | INVOKER | |
| texticregexeq(citext, citext) | FUNCTION | internal | true | boolean | INVOKER | |
| citext(inet) | FUNCTION | internal | true | citext | INVOKER | |
| get_last_message(p_stream_id integer) | FUNCTION | plpgsql | false | chat_messages | INVOKER | Returns the most recent non-deleted chat message in a given stream. |
| citext_hash(citext) | FUNCTION | c | true | integer | INVOKER | |
| update_user_description(p_user_id integer, p_description text) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Updates the description/bio of a user. |
| create_permission(p_name text) | FUNCTION | plpgsql | false | SETOF permissions | INVOKER | Creates a new permission if it does not already exist. Returns the existing or newly created permission. |
| gen_random_bytes(integer) | FUNCTION | c | false | bytea | INVOKER | |
| texticregexne(citext, citext) | FUNCTION | internal | true | boolean | INVOKER | |
| edit_chat_message(p_message_id integer, p_new_content text) | FUNCTION | plpgsql | false | boolean | INVOKER | Updates the content of a chat message and records the old content in the edit history. |
| update_stream_token(p_user_id integer) | FUNCTION | plpgsql | false | SETOF users | INVOKER | Generates and assigns a new random stream token to a user. |
| digest(text, text) | FUNCTION | c | true | bytea | INVOKER | |
| check_if_stream_exists(p_stream_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | |
| translate(citext, citext, text) | FUNCTION | sql | true | text | INVOKER | |
| assign_role_to_user_by_role_id(p_user_id integer, p_role_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Assigns a role to a user globally (without context). Returns TRUE if successful. |
| citext_cmp(citext, citext) | FUNCTION | c | true | integer | INVOKER | |
| delete_role_by_id(p_role_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Deletes a role by ID if no permissions are assigned to it. Returns TRUE on success, FALSE if permissions are assigned. |
| delete_chat_message(p_message_id integer) | FUNCTION | plpgsql | false | boolean | INVOKER | Marks a chat message as deleted (soft delete). |
| create_statistic_type(p_name text, p_description text DEFAULT NULL::text) | FUNCTION | plpgsql | false | stream_statistics_types | INVOKER | Creates a new stream statistic type with the given name and optional description. Returns the newly created statistic type. If a type with the same name already exists, returns the existing type. |
| citext(character) | FUNCTION | internal | true | citext | INVOKER | |
| gen_salt(text, integer) | FUNCTION | c | false | text | INVOKER | |
| revoke_refresh_token(p_token_hash text, p_revoke_session boolean DEFAULT false) | FUNCTION | plpgsql | false | boolean | INVOKER | Revokes a refresh token and optionally revokes its associated session. |
| count_message_edits(p_message_id integer) | FUNCTION | plpgsql | false | integer | INVOKER | Returns the number of edits made to a given chat message. |