Lotus.Storage.Query (Lotus v0.9.2)
View SourceRepresents 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.
Summary
Functions
Extracts unique variable names from an SQL statement in order of first occurrence.
Types
@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()] }
Functions
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")
[]