Lotus.Storage.QueryVariable (Lotus v0.9.2)

View Source

Represents a variable placeholder ({{var}}) used inside a Lotus query.

Each variable defines:

  • :name — the identifier used in the SQL statement
  • :type — how the value is interpreted (text, number, date)
  • :widget — how the value should be collected in the UI (input, select)
  • :label — a human-friendly label shown in the UI
  • :default — fallback value if none is provided
  • :static_options — hardcoded list of allowed values (for selects) Can be either a list of strings or a list of {value, label} tuples
  • :options_query — SQL to dynamically populate allowed values

Validation ensures that when a variable is configured as a :select widget, it must have either :static_options or :options_query.

Summary

Functions

Determines the source of options for a query variable.

Types

t()

@type t() :: %Lotus.Storage.QueryVariable{
  default: String.t() | nil,
  label: String.t() | nil,
  name: String.t(),
  options_query: String.t() | nil,
  static_options: [Lotus.Storage.QueryVariable.StaticOption.t()],
  type: :text | :number | :date,
  widget: :input | :select | nil
}

Functions

changeset(variable, attrs \\ %{})

get_option_source(arg1)

@spec get_option_source(t()) :: :query | :static

Determines the source of options for a query variable.

Returns :query if the variable has a non-empty options_query, otherwise returns :static.

Examples

iex> var = %Lotus.Storage.QueryVariable{options_query: "SELECT id, name FROM users"}
iex> Lotus.Storage.QueryVariable.get_option_source(var)
:query

iex> var = %Lotus.Storage.QueryVariable{options_query: "   "}
iex> Lotus.Storage.QueryVariable.get_option_source(var)
:static

iex> var = %Lotus.Storage.QueryVariable{static_options: ["a", "b"]}
iex> Lotus.Storage.QueryVariable.get_option_source(var)
:static

iex> var = %Lotus.Storage.QueryVariable{static_options: [{"val", "Label"}]}
iex> Lotus.Storage.QueryVariable.get_option_source(var)
:static