FIQLEx v0.1.8 FIQLEx View Source

FIQL (Feed Item Query Language) is a URI-friendly syntax for expressing filters.

FIQL looks like this:

fiql = "author.age=ge=25;author.name==*Doe"

Using this module you will be able to parse a FIQL string and to build a query for any system (SQL, Elasticsearch, etc...) from it.

Given a FIQL string like:

fiql = "author.age=ge=25;author.name==*Doe"

Pass it to the parse/1 or parse1!/1 functions to retrieve an AST of the FIQL string:

{:ok, ast} = FIQLEx.parse(fiql)

Then you can use this AST to build you own query for your system or use our built-in query builders like FIQLEx.QueryBuilders.SQLQueryBuilder:

{:ok, sql_query} = FIQLEx.build_query(ast, FIQLEx.QueryBuilders.SQLQueryBuilder, table: "author")

Here, sql_query is SELECT * FROM author WHERE (author.age >= 25 AND author.name LIKE '%Doe').

You can use your own query builder by providing your own module that uses FIQLEx.QueryBuilder as second argument of build_query/3.

Link to this section Summary

Functions

Use an AST to build a query in the way you want. For instance you could create a query for Elasticsearch from a FIQL AST, or use the FIQLEx.QueryBuilders.SQLQueryBuilder module to build an SQL query from a FIQL AST.

This function will go deeper in the ast traversal.

Same as handle_ast/4 but returns the state or raises an exception.

Parses the FIQL string and returns an AST representation of the query to be built to any other query (SQL, Elasticsearch) with the build_query/3 function.

Same as parse/1 but returns the AST or raises an exception.

Link to this section Types

Link to this section Functions

Link to this function

build_query(ast, module, opts \\ [])

View Source
build_query(ast(), atom(), Keyword.t()) :: {:ok, any()} | {:error, any()}

Use an AST to build a query in the way you want. For instance you could create a query for Elasticsearch from a FIQL AST, or use the FIQLEx.QueryBuilders.SQLQueryBuilder module to build an SQL query from a FIQL AST.

Parameters are:

  • ast: The AST to transform to a query for another system
  • module: The module to use for the AST traversal
  • opts: Options you want to pass to the init/2 function of your module

This function returns {:ok, query} with your created query if everything is fine, or {:error, reason} if there is something wrong.

query = "author.age=ge=25;author.name==*Doe"
{:ok, ast} = FIQLEx.parse(query)
{:ok, query} = FIQLEx.build_query(ast, MyQueryBuilder)

See the documentation of the FIQLEx.QueryBuilder module to learn more about the AST traversal.

Link to this function

handle_ast(curr_ast, ast, module, state)

View Source
handle_ast(ast(), ast(), atom(), any()) :: {:ok, any()} | {:error, any()}

This function will go deeper in the ast traversal.

Parameters are:

  • curr_ast: The AST we want to go deeper with
  • ast: The global AST
  • module: The module to use for the traversal
  • state: The current state of your query builder

The function returns {:ok, state} if everything is fine, and {:error, reason} if there is an error

Link to this function

handle_ast!(curr_ast, ast, module, state)

View Source
handle_ast!(ast(), ast(), atom(), any()) :: any()

Same as handle_ast/4 but returns the state or raises an exception.

Link to this function

parse(str)

View Source
parse(binary()) :: {:ok, ast()} | {:error, any()}

Parses the FIQL string and returns an AST representation of the query to be built to any other query (SQL, Elasticsearch) with the build_query/3 function.

Returns {:ok, ast} if everything is fine and {:error, reason} in case of error in the FIQL.

Same as parse/1 but returns the AST or raises an exception.