View Source Loupe.Language.Ast (Loupe v0.7.0)

Extracted AST structure query.

It uses a basic syntax like

[action] [quantifier?] [schema] where [predicates]

The action is any alphanumeric value. It can be used to specify what do you aim to use the query for. It could ̀ecto for instance that you query Ecto with, or even ets that lookup an ets table with match spec.

The quantifier is used to limit the queries result but can be ommited defaulting to 1. It supports the following:

  • Positive integer; 1, 2, 10 etc...
  • Range: 10..20, it limits the query to 10 records offsetting to the 10th record
  • all: Returns all the record matching

The schema needs to be an idenfifier (non-quoted alphanumeric) that matches the definition's schemas/1 function.

The predicates are combination of boolean operators and operand for validation. See the module's type for every support operators but it can basically be a syntax like

# could match `get` and run query on Ecto.
get 5 User where (name = "John Doe") or (age > 18)

# count match `protobuf` to query Ecto and generate Protobufs.
protobuf all BoardGame where name like "Catan"

Link to this section Summary

Types

Alpha identifier

Composed bidings from nested querying

Valid boolean operators

Literial values usable in comparison

Valid comparison operands

Validation composed predicates

Query quantifier to limit the query result count

Range from one value to another

Reserved keywords

t()

Functions

Extracts bindings of an AST

Link to this section Types

@type alpha_identifier() :: charlist()

Alpha identifier

@type binding() :: {:binding, [binary()]}

Composed bidings from nested querying

@type boolean_operator() :: :or | :and

Valid boolean operators

@type literal() ::
  {:float, float()}
  | {:int, integer()}
  | {:string, binary()}
  | {:sigil, binary()}

Literial values usable in comparison

@type operand() :: := | :> | :>= | :< | :<= | :like | :in

Valid comparison operands

@type predicate() ::
  {boolean_operator(), predicate(), predicate()}
  | {operand(), binding(), literal()}
  | nil

Validation composed predicates

@type quantifier() :: :all | {:int, integer()} | {:range, range()}

Query quantifier to limit the query result count

@type range() :: {integer(), integer()}

Range from one value to another

@type reserved_keyword() :: :empty

Reserved keywords

@type t() :: %Loupe.Language.Ast{
  action: binary(),
  predicates: predicate(),
  quantifier: quantifier(),
  schema: binary()
}

Link to this section Functions

@spec bindings(t()) :: [[binary()]]

Extracts bindings of an AST

Link to this function

new(action, binding, quantifier, predicates)

View Source

Instanciates the AST