PgFlow.Queries.Helpers (PgFlow v0.1.0)

Copy Markdown View Source

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

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.

Parses a UUID string to binary format for database queries.

Converts a status atom or string to string for database queries.

Converts a time range atom to a start DateTime.

Functions

direction_to_string(dir)

@spec direction_to_string(:next | :prev | String.t()) :: String.t()

Converts a direction atom to string for database queries.

execute_rpc(repo, function_name, params, opts \\ [])

@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 repository
  • function_name - Name of the PostgreSQL function
  • params - List of parameters to pass
  • opts - 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

format_uuid(uuid)

@spec format_uuid(nil | binary()) :: nil | String.t()

Formats a binary UUID to string representation.

health_status_to_string(status)

@spec health_status_to_string(nil | atom() | String.t()) :: nil | String.t()

Converts a health status atom or string to string for database queries.

parse_uuid(uuid)

@spec parse_uuid(nil | String.t() | binary()) :: nil | binary()

Parses a UUID string to binary format for database queries.

status_to_string(status)

@spec status_to_string(nil | atom() | String.t()) :: nil | String.t()

Converts a status atom or string to string for database queries.

time_range_start(arg1)

@spec time_range_start(atom()) :: DateTime.t()

Converts a time range atom to a start DateTime.