ExSQL.AST.Select (exsql v0.1.2)

Copy Markdown

A SELECT statement.

columns is a list of :star, {:qualified_star, table}, or {expr, alias | nil} tuples. Expressions are tagged tuples as produced by ExSQL.Parser — see that module for the expression grammar.

from is a join tree:

  • nil — no FROM clause
  • {:table, name, alias | nil}

  • {:subquery, %Select{}, alias | nil}

  • {:join, type, left, right, constraint} where type is %{natural: boolean, left: boolean}, left is a join tree, right a single source, and constraint is nil, {:on, expr}, or {:using, [name]}. Comma joins, CROSS JOIN, and INNER JOIN all parse to left: false — they differ only as planner hints in SQLite.

Summary

Types

constraint()

@type constraint() :: nil | {:on, expr()} | {:using, [String.t()]}

expr()

@type expr() :: ExSQL.Parser.expr()

join_type()

@type join_type() :: %{natural: boolean(), left: boolean()}

source()

@type source() ::
  {:table, String.t(), String.t() | nil}
  | {:subquery, t(), String.t() | nil}
  | {:join, join_type(), source(), source(), constraint()}

t()

@type t() :: %ExSQL.AST.Select{
  columns: [:star | {:qualified_star, String.t()} | {expr(), String.t() | nil}],
  distinct: boolean(),
  from: source() | nil,
  group_by: [expr()],
  having: expr() | nil,
  limit: expr() | nil,
  offset: expr() | nil,
  order_by: [{expr(), :asc | :desc}],
  where: expr() | nil,
  windows: %{required(String.t()) => map()}
}