README.md

# erlquery

The erlquery parser and codegen core library. Meant to be used in tools like rebar plugins.

## Build

    rebar3 compile
        
## Test

    rebar3 eunit

## Usage

Include in deps:

    erlquery

erlquery can parse .erlq files into configs, and generate erlang modules based on these configs.

It is designed to be used with other tools like rebar3. Check out [rebar3_erlquery](https://git.sr.ht/~fancycade/rebar3_erlquery) for usage instructions.

Make an erlq module like this:

    -module(example).

    -query(pgo:query/2).

    select_todos ->
        SELECT * FROM todos.

This file can be parsed into a config:

    {ok, Config} = erlquery:parse("example.erlq").

To generate the erlang module:

    {ok, Bin} = erlquery:codegen(Config).

The generated erlang code will look like this:

    -module(example).

    -export([select_todos/1]).

    select_todos(Args) ->
        pgo:query(<<"SELECT * FROM todos">>, Args).

We can compile this erlang code into BEAM bytecode:

    file:write_file("example.erl", Bin),
    {ok, example} = compile:file("example.erl").

Now the example module will be loaded into the Erlang environment and it can be used.

    example:select_todos([]).

The argument of a function generated by erlquery will always be a list. This is the args list.

# License

Apache 2.0