Shared utilities for database queries.
Provides RPC-style PostgreSQL function calls, UUID handling, row-to-map conversion, time range calculations, and status conversions.
Used by both PgFlow core query modules and the PgFlow Dashboard.
Summary
Functions
Casts a UUID to its canonical string form and fails closed for invalid IDs.
Converts a direction atom to string for database queries.
Executes an RPC-style call to a PostgreSQL function.
Formats a binary UUID to string representation.
Converts a health status atom or string to string for database queries.
Casts an optional UUID while preserving nil.
Parses a UUID string to binary format for database queries.
Returns a positive :limit option or the supplied positive default.
Converts a status atom or string to string for database queries.
Converts a time range atom to a start DateTime.
Functions
@spec cast_uuid(term()) :: {:ok, Ecto.UUID.t()} | {:error, :invalid_id}
Casts a UUID to its canonical string form and fails closed for invalid IDs.
Converts a direction atom to string for database queries.
@spec execute_rpc(module(), String.t(), list(), keyword()) :: {:ok, nil | map() | [map()]} | {:error, :not_found | term()} | [map()] | integer()
Executes an RPC-style call to a PostgreSQL function.
Parameters
repo- The Ecto repositoryfunction_name- Name of the PostgreSQL functionparams- List of parameters to passopts- Options keyword list
Options
:schema- (required) The PostgreSQL schema containing the function:mode- Result handling mode::list,:single,:count,:void,:raw
Returns
Depends on mode:
:list- Returns list of maps:single- Returns{:ok, map}or{:error, :not_found}:count- Returns integer count:void- Returns{:ok, nil}:raw- Returns{:ok, list of maps}or error
Formats a binary UUID to string representation.
Converts a health status atom or string to string for database queries.
@spec optional_uuid(term()) :: {:ok, Ecto.UUID.t() | nil} | {:error, :invalid_id}
Casts an optional UUID while preserving nil.
Parses a UUID string to binary format for database queries.
@spec positive_limit( keyword(), pos_integer() ) :: pos_integer()
Returns a positive :limit option or the supplied positive default.
Converts a status atom or string to string for database queries.
@spec time_range_start(atom()) :: DateTime.t()
Converts a time range atom to a start DateTime.