# `Lotus.Storage.Query`
[🔗](https://github.com/typhoonworks/lotus/blob/v0.16.6/lib/lotus/storage/query.ex#L1)

Represents a saved Lotus query.

Queries can be stored, updated, listed, and executed by the host app.
Supports `{{var}}` placeholders in the SQL `statement` for value substitution
only. Variables are bound at runtime using configured variables and are only
safe for SQL values (WHERE clauses, ORDER BY values, etc.), never for
identifiers like table names, column names, or schema names.

# `t`

```elixir
@type t() :: %Lotus.Storage.Query{
  __meta__: term(),
  data_repo: String.t() | nil,
  description: String.t() | nil,
  id: term(),
  inserted_at: DateTime.t(),
  name: String.t(),
  search_path: String.t() | nil,
  statement: String.t(),
  updated_at: DateTime.t(),
  variables: [Lotus.Storage.QueryVariable.t()]
}
```

# `changeset`

# `extract_optional_variable_names`

```elixir
@spec extract_optional_variable_names(String.t()) :: MapSet.t()
```

Returns a `MapSet` of variable names that appear inside `[[...]]` optional
clause blocks in the given SQL statement.

# `extract_variables_from_statement`

```elixir
@spec extract_variables_from_statement(String.t()) :: [String.t()]
```

Extracts unique variable names from an SQL statement in order of first occurrence.

Variables are identified by the `{{variable_name}}` syntax.

## Examples

    iex> Lotus.Storage.Query.extract_variables_from_statement("SELECT * FROM users WHERE id = {{user_id}} AND status = {{status}}")
    ["user_id", "status"]

    iex> Lotus.Storage.Query.extract_variables_from_statement("SELECT * FROM users WHERE id = {{user_id}} OR id = {{user_id}}")
    ["user_id"]

    iex> Lotus.Storage.Query.extract_variables_from_statement("SELECT * FROM users")
    []

# `new`

# `to_sql_params`

```elixir
@spec to_sql_params(t(), map()) :: {String.t(), [term()]}
```

# `update`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
