Archeometer.Query.Term (Archeometer v0.5.0)

Restrict and adapt Elixir terms to a subset that is translatable to SQLite expressions. See the language reference

The following literals are allowed

  • Integers
  • Floating point numbers
  • Bitstrings
  • Booleans
  • Lists

Plus some operators and functions

  • Boolean operators: and, or, not
  • Comparaison operators: ==, !=, <, >, <=, >=
  • Arithmetic operators: +, -, *, /
  • Arithmetic functions: round
  • Search functions: like
  • Null checking: is_nil, not is_nil
  • Aggregation functions: avg, count, max, min, sum
  • Subquery expressions: exists
  • in operator

And any kind of dot operator: m.some.key.or.attribute to represent table lookup. For example

max(m.num_lines, 10 * m.num_args)

m.cc > 10

like(m.name, "Archeometer.%") and m.name != "Archeometer.Query.Term"

Tuples and maps are allowed but only as a top level construct.

{m.name, m.num_lines, avg(m.functions.cc)} # this is valid
[name, num_lines * 10] # this as well

{m.name, {m.functions.name, m.functions.num_lines}} # this is not
[m.name, {m.num_lines}] # neither is this

Link to this section Summary

Functions

Takes a validated AST and tries to transformed into its original state.

Takes a validated AST and tries to transformed into an SQL-compatible io_data. The goal would be to obtain valid SQL just by calling IO.iodata_to_binary/1.

Takes an AST and returns a validated AST.For the most part it is identical to the original, except with anotated symbols.lookups instead of dot operators.

Link to this section Functions

Link to this function

to_ast(validated_ast)

Takes a validated AST and tries to transformed into its original state.

Most of the metadata is long gone by this point, but at least the original structure is preserved.

Takes a validated AST and tries to transformed into an SQL-compatible io_data. The goal would be to obtain valid SQL just by calling IO.iodata_to_binary/1.

Takes an AST and returns a validated AST.For the most part it is identical to the original, except with anotated symbols.lookups instead of dot operators.