View Source Loupe.Language.GetAst (Loupe v0.3.0)

Extracted AST structure from a get query.

It uses a basic syntax like

get [quantifier?] [schema] where [predicates]

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

get 5 User where (name = "John Doe") or (age > 18)

Link to this section Summary

Types

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()

Link to this section Types

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

Literial values usable in comparison

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

Valid comparison operands

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

Validation composed predicates

@type quantifier() :: :all | {:int, integer()} | 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.GetAst{
  predicates: predicate(),
  quantifier: quantifier(),
  schema: binary()
}

Link to this section Functions

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

Extracts bindings of an AST

Link to this macro

is_boolean_operator(boolean_operator)

View Source (macro)
Link to this macro

is_literal(literal)

View Source (macro)
Link to this macro

is_operand(operand)

View Source (macro)
Link to this macro

is_reserved_keyword(reserved_keyword)

View Source (macro)
Link to this macro

is_text_operand(operand)

View Source (macro)
Link to this function

new(binding, quantifier, predicates)

View Source
@spec new(binding(), quantifier(), predicate()) :: t()

Instanciates the AST