View Source Electric.Replication.Eval.Parser (electric v1.0.1)
Summary
Functions
Parses and validates a WHERE clause in PostgreSQL SQL syntax.
Types
@type parse_opt() :: {:env, Electric.Replication.Eval.Env.t()} | {:refs, refs_map()} | {:params, %{required(String.t()) => String.t()}}
@type refs_map() :: %{ optional([String.t(), ...]) => Electric.Replication.Eval.Env.pg_type() }
@type tree_part() :: %Electric.Replication.Eval.Parser.Const{ location: term(), meta: term(), type: term(), value: term() } | %Electric.Replication.Eval.Parser.Ref{ location: term(), path: term(), type: term() } | %Electric.Replication.Eval.Parser.Func{ args: term(), immutable?: term(), implementation: term(), location: term(), map_over_array_in_pos: term(), name: term(), strict?: term(), type: term(), variadic_arg: term() } | %Electric.Replication.Eval.Parser.Array{ elements: term(), location: term(), type: term() }
Functions
@spec parse_and_validate_expression(String.t(), [parse_opt()]) :: {:ok, Electric.Replication.Eval.Expr.t()} | {:error, String.t()}
Parses and validates a WHERE clause in PostgreSQL SQL syntax.
Returns a tuple of {:ok, Expr.t()}
or {:error, String.t()}
.
Query may contain $1
parameter references, which will be taken from a params
keyword argument.
params
must be a map with both strings and values as keys. Because we're using this query later in
places that won't support parameter references, the Expr
will have a query
field that contains
normalized query with parameters substrituted with strings with explicit type casts. For example:
{:ok, %Expr{query: "1 > '0'::int4"}} =
Parser.parse_and_validate_expression("1 > $1", params: %{"1" => "0"})
Query will be always be normalized, i.e. extra whitespace removed and keywords converted to upper case.
@spec parse_and_validate_expression!(String.t(), [parse_opt()]) :: Electric.Replication.Eval.Expr.t()