FIQLEx v0.1.0 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
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 systemmodule
: The module to use for the AST traversalopts
: Options you want to pass to theinit/2
function of yourmodule
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.
This function will go deeper in the ast traversal.
Parameters are:
curr_ast
: The AST we want to go deeper withast
: The global ASTmodule
: The module to use for the traversalstate
: The current state of your query builder
The function returns {:ok, state}
if everything is fine, and {:error, reason}
if there is an error
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.
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.