# `Electric.Replication.Eval.Parser`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/replication/eval/parser.ex#L1)

# `parse_opt`

```elixir
@type parse_opt() ::
  {:env, Electric.Replication.Eval.Env.t()}
  | {:refs, refs_map()}
  | {:params, %{required(String.t()) =&gt; String.t()}}
```

# `refs_map`

```elixir
@type refs_map() :: %{
  optional([String.t(), ...]) =&gt; Electric.Replication.Eval.Env.pg_type()
}
```

# `tree_part`

```elixir
@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()
    }
```

# `extract_parts_from_select`

# `extract_subqueries`

# `find_refs`

# `parse_and_validate_expression`

```elixir
@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:

```elixir
{: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.
```

# `parse_and_validate_expression!`

```elixir
@spec parse_and_validate_expression!(String.t(), [parse_opt()]) ::
  Electric.Replication.Eval.Expr.t()
```

# `parse_query`

Parses a query into a Postgres AST

# `unwrap_node_string`

# `validate_order_by`

# `validate_where_ast`

---

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