View Source a_tree (a_tree v0.2.1)

A module for interacting with an ATree.

Examples

1> {ok, Tree} = a_tree:new([
    {boolean, <<"private">>},
    {string, <<"country">>},
    {integer, <<"exchange_id">>},
    {string, <<"city">>},
    {string_list, <<"deals">>},
    {integer_list, <<"segment_ids">>}
]).
2> ok = a_tree:insert(Tree, 1, <<"exchange_id = 1 and not private and deals one of [\"deal-1\", \"deal-2\"]">>).
3> ok = a_tree:insert(Tree, 2, <<"exchange_id = 1 and not private and deals one of [\"deal-2\", \"deal-3\"] and segment_ids one of [1, 2, 3, 4]">>).
4> ok = a_tree:insert(Tree, 3, <<"exchange_id = 1 and not private and deals one of [\"deal-2\", \"deal-3\"] and segment_ids one of [5, 6, 7, 8] and country in [\"CA\", \"US\"]">>).
5> {ok, Results} = a_tree:search([
    {<<"private">>, false},
    {<<"exchange_id">>, 1},
    {<<"deals">>, [<<"deal-1">>, <<"deal-3">>]},
    {<<"segment_ids">>, [2, 3]},
    {<<"country">>, <<"CA">>}
]).

Link to this section Summary

Functions

Remove the specified boolean expression from the t:atree/0.

Insert a new arbitrary boolean expression inside the t:atree/0 with the specified t:user_id/0.

Create a new t:atree/0.

Search for boolean expressions that match the specified event.

Link to this section Types

-opaque atree()
-type attribute() :: {attribute_type(), attribute_name()}.
-type attribute_name() :: binary().
-type attribute_type() :: boolean | integer | string | integer_list | string_list.
-type attribute_value() :: boolean() | binary() | integer() | [integer()] | [binary()].
-type event() :: [{attribute_name(), attribute_value()}].
-type user_id() :: non_neg_integer().

Link to this section Functions

-spec delete(ATree :: atree(), Id :: user_id()) -> ok.

Remove the specified boolean expression from the t:atree/0.

Link to this function

insert(ATree, Id, Expression)

View Source
-spec insert(ATree :: atree(), Id :: user_id(), Expression :: binary()) -> ok | {error, term()}.

Insert a new arbitrary boolean expression inside the t:atree/0 with the specified t:user_id/0.

The boolean expression must contain defined attributes with the correct types otherwise an error will be returned.

-spec new(Attributes :: [attribute()]) -> {ok, atree()} | {error, term()}.

Create a new t:atree/0.

The attributes must all be different otherwise an error will be returned.

-spec search(ATree :: atree(), Event :: event()) -> {ok, Matches :: [user_id()]} | {error, term()}.

Search for boolean expressions that match the specified event.