View Source Loupe.Language.Ast (Loupe v0.9.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

Parameters provided to the query

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 alpha_identifier() :: charlist()

Alpha identifier

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

Composed bidings from nested querying

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

Valid boolean operators

Link to this type

external_identifiers()

View Source
@type external_identifiers() :: MapSet.t(String.t())
@type literal() ::
  {:float, float()}
  | {:int, integer()}
  | {:string, binary()}
  | {:sigil, binary()}
  | {:identifier, binary()}

Literial values usable in comparison

@type object() :: {:object, [{binary(), literal() | object()}]}
@type operand() :: := | :> | :>= | :< | :<= | :like | :in

Valid comparison operands

@type parameters() :: map()

Parameters provided to the query

@type predicate() ::
  {boolean_operator(), predicate(), predicate()}
  | {operand(), binding(), literal()}
  | {:not, {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(),
  external_identifiers: external_identifiers(),
  parameters: parameters(),
  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, parameters \\ nil)

View Source
@spec new(
  alpha_identifier(),
  alpha_identifier(),
  quantifier(),
  predicate(),
  object() | nil
) :: t()

Instanciates the AST

Link to this function

unwrap_literal(arg, external_identifiers)

View Source
@spec unwrap_literal(literal() | object(), external_identifiers()) ::
  {any(), external_identifiers()}

Unwraps literal