barrel_bql (barrel_docdb v1.1.1)

View Source

BQL, barrel's PartiQL dialect: the public compile surface.

Pipeline: lex -> parse -> canonicalize -> validate -> lower. The resulting plan carries a barrel_query spec for the document scan, an optional table-function source (executed by the barrel module, never here), an optional unnest, and per-row post stages.

  {ok, Plan} = barrel_bql:compile(
      <<"SELECT title FROM db WHERE type = 'post' LIMIT 10">>),
  {ok, Plan2} = barrel_bql:compile(
      <<"SELECT * FROM db WHERE org = $org">>,
      #{params => #{<<"org">> => <<"acme">>}}).

Summary

Functions

Compile BQL source (or a parsed AST) to an executable plan.

One-line human rendering of a compile error, for logs and the REST 400 body.

Parse BQL source to its AST. Locations are {Line, Column}.

Types

bql_error/0

-type bql_error() :: {parse_error, loc(), binary()} | {invalid_query, loc() | undefined, tuple()}.

loc/0

-type loc() :: barrel_bql_ast:loc().

plan/0

-type plan() :: barrel_bql_lower:plan().

Functions

compile(Input)

-spec compile(binary() | string() | barrel_bql_ast:ast()) -> {ok, plan()} | {error, bql_error()}.

Compile BQL source (or a parsed AST) to an executable plan.

compile(Ast, Opts)

-spec compile(binary() | string() | barrel_bql_ast:ast(), #{params => #{binary() => term()}}) ->
                 {ok, plan()} | {error, bql_error()}.

format_error(_)

-spec format_error(bql_error()) -> binary().

One-line human rendering of a compile error, for logs and the REST 400 body.

parse(Source)

-spec parse(binary() | string()) -> {ok, barrel_bql_ast:ast()} | {error, bql_error()}.

Parse BQL source to its AST. Locations are {Line, Column}.