qlc v1.0.6 Qlc View Source
Link to this section Summary
Types
key position for sorting tuples
order function
order option
sorting option
unique option for sorting
Functions
variable binding list to erlang_binding list
create qlc cursor from qlc_handle
delete qlc cursor
eval qlc_handle
erlang ast with binding variables to qlc_handle
string to erlang ast
fold qlc_handle with accumulator
sorts tuples on query_handle
optoin list to record(:qlc_opt)
string to qlc_handle with variable bindings
Returns a query handle
string to qlc_handle with variable bindings
create qlc handle for any. see :qlc.table/2
Link to this section Types
abstract_expr()
View Source
abstract_expr() :: :erl_parse.abstract_expr()
abstract_expr() :: :erl_parse.abstract_expr()
binding_struct()
View Source
binding_struct() :: :erl_eval.binding_struct()
binding_struct() :: :erl_eval.binding_struct()
bindings()
View Source
bindings() :: Keyword.t()
bindings() :: Keyword.t()
error_info()
View Source
error_info() :: :erl_parse.error_info()
error_info() :: :erl_parse.error_info()
expr()
View Source
expr() :: :erl_parse.abstract_expr()
expr() :: :erl_parse.abstract_expr()
key_pos()
View Source
key_pos() :: non_neg_integer() | [non_neg_integer()]
key_pos() :: non_neg_integer() | [non_neg_integer()]
key position for sorting tuples.
indexed by 0 (elixir's tuple element indexing).
object_list()
View Source
object_list() :: traverse_fun0() | objects()
object_list() :: traverse_fun0() | objects()
objects()
View Source
objects() :: [] | [term() | object_list()]
objects() :: [] | [term() | object_list()]
order_fun() View Source
order function
detect order if smaller =< bigger then return true else false.
order_option()
View Source
order_option() :: :ascending | :descending | order_fun()
order_option() :: :ascending | :descending | order_fun()
order option
order by elixir native ascending, descending or order_fun(). default is ascending.
qlc_lc()
View Source
qlc_lc() :: any()
qlc_lc() :: any()
qlc_opt()
View Source
qlc_opt() :: tuple()
qlc_opt() :: tuple()
qlc_opt_list() View Source
query_cursor()
View Source
query_cursor() :: Qlc.Cursor.t()
query_cursor() :: Qlc.Cursor.t()
query_handle()
View Source
query_handle() :: :qlc.query_handle()
query_handle() :: :qlc.query_handle()
sort_option()
View Source
sort_option() :: {:order, order_option()} | unique_option() | any()
sort_option() :: {:order, order_option()} | unique_option() | any()
sorting option.
see :qlc.sort/2
sort_options()
View Source
sort_options() :: [sort_option()] | sort_option()
sort_options() :: [sort_option()] | sort_option()
table_options() View Source
traverse_fun()
View Source
traverse_fun() :: traverse_fun0() | traverse_fun1()
traverse_fun() :: traverse_fun0() | traverse_fun1()
traverse_fun0()
View Source
traverse_fun0() :: (() -> traverse_result())
traverse_fun0() :: (() -> traverse_result())
traverse_fun1()
View Source
traverse_fun1() :: (:ets.match_spec() -> traverse_result())
traverse_fun1() :: (:ets.match_spec() -> traverse_result())
traverse_result() View Source
unique_option()
View Source
unique_option() :: {:unique, boolean()}
unique_option() :: {:unique, boolean()}
unique option for sorting.
only the first of a sequence of terms that compare equal(==) is output if this option is set to true. defaults to false.
Link to this section Functions
bind(a)
View Source
bind(Keyword.t()) :: binding_struct()
bind(Keyword.t()) :: binding_struct()
bind(list, b)
View Source
bind(Keyword.t(), binding_struct()) :: binding_struct()
bind(Keyword.t(), binding_struct()) :: binding_struct()
variable binding list to erlang_binding list
cursor(qh)
View Source
cursor(query_handle()) :: query_cursor()
cursor(query_handle()) :: query_cursor()
create qlc cursor from qlc_handle
(create processes)
delete_cursor(qc)
View Source
delete_cursor(Qlc.Cursor.t()) :: :ok
delete_cursor(Qlc.Cursor.t()) :: :ok
delete qlc cursor
(kill processes)
e(qh)
View Source
e(query_handle()) :: list()
e(query_handle()) :: list()
eval qlc_handle
expr_to_handle(expr, bind, opt)
View Source
expr_to_handle(expr(), binding_struct(), qlc_opt_list()) ::
query_handle() | {:qlc_handle, tuple()}
expr_to_handle(expr(), binding_struct(), qlc_opt_list()) :: query_handle() | {:qlc_handle, tuple()}
erlang ast with binding variables to qlc_handle
exprs(str) View Source
string to erlang ast
fold(qh, a, f, option \\ []) View Source
fold qlc_handle with accumulator
example
iex> require Qlc
iex> list = [a: 1,b: 2,c: 3]
iex> qlc_handle = Qlc.q("[X || X = {K,V} <- L, K =/= Item]",
...> [L: list, Item: :b])
...> Qlc.fold(qlc_handle, [], fn({k,v}, acc) ->
...> [{v, k}|acc]
...> end)
[{3, :c}, {1, :a}]
keysort(qh, keypos, opt \\ [])
View Source
keysort(query_handle(), key_pos(), sort_options()) :: query_handle()
keysort(query_handle(), key_pos(), sort_options()) :: query_handle()
sorts tuples on query_handle.
The sort is performed on the element(s) mentioned in key_pos. If two tuples compare equal (==) on one element, the next element according to key_pos is compared. The sort is stable. key_pos is indexing by 0.
example
iex> list = [a: 3, b: 2, c: 1]
iex> Qlc.q("[ X || X <- L]", [L: list]) |>
...> Qlc.keysort(1, order: :ascending) |>
...> Qlc.e()
[c: 1, b: 2, a: 3]
iex> list = [a: 1, b: 2, c: 3, d: 2]
...> Qlc.q("[X || X <- L]", [L: list]) |>
...> Qlc.keysort(1, order: :descending, unique: true) |>
...> Qlc.e()
[c: 3, b: 2, a: 1]
options(opt, tagname, field_defs) View Source
optoin list to record(:qlc_opt)
q(string, bindings, opt \\ []) View Source (macro)
string to qlc_handle with variable bindings.
string may be literal or variable. If string is variable or function call, then expanding to string_to_handle/3 automatically. elixir expression using bang macro are available to interpolation, but expanding to erlang expression string. see examples.
syntax
[Expression || Qualifier1, Qualifier2, ...]
Expression :: arbitary Erlang term (the template)
Qualifier :: Filter or Generators
Fiilter :: Erlang expressions returning bool()
Generator :: Pattern <- ListExpression
ListExpression :: Qlc_handle or list()
Qlc_handle :: returned from Qlc.table/2, Qlc.sort/2, Qlc.keysort/3
Qlc.q/2, Qlc.string_to_handle/2
example
iex> require Qlc
iex> list = [a: 1,b: 2,c: 3]
iex> qlc_handle = Qlc.q("[X || X = {K,V} <- L, K =/= Item]",
...> [L: list, Item: :b])
...> Qlc.e(qlc_handle)
[a: 1, c: 3]
...> Qlc.q("[X || X = {K, V} <- L, K =:= Item]",
...> [L: qlc_handle, Item: :c]) |>
...> Qlc.e
[c: 3]
...> query_string = "[X || X = {K, V} <- L, K =:= Item]"
...> bindings = [L: list, Item: :b]
...> Qlc.q(query_string, bindings) |> Qlc.e()
[b: 2]
iex> ## Qlc.Record.defrecord(:user, [id: nil, name: nil, age: nil])
iex> list = [user(id: 1, name: :foo, age: 10),
...> user(id: 2, name: :bar, age: 20),
...> user(id: 3, name: :baz, age: 30)]
...> query_string = "[X || X <- L, #{user!(X, :age)} < Age]"
...> bindings = [L: list, Age: 20]
...> Qlc.q(query_string, bindings) |> Qlc.e()
[{:user, 1, :foo, 10}]
qlc_handle(args \\ []) View Source (macro)
qlc_handle(record, args) View Source (macro)
qlc_lc(args \\ []) View Source (macro)
qlc_lc(record, args) View Source (macro)
qlc_opt(args \\ []) View Source (macro)
qlc_opt(record, args) View Source (macro)
sort(qh, opt)
View Source
sort(query_handle(), sort_options()) :: query_handle()
sort(query_handle(), sort_options()) :: query_handle()
Returns a query handle.
When evaluating returned query handle, the answers to query handle argument are sorted by the query_handle() options.
example
iex> list = [a: 3, b: 2, c: 1]
iex> Qlc.q("[ X || X <- L]", [L: list]) |>
...> Qlc.sort(order: :descending) |>
...> Qlc.e()
[c: 1, b: 2, a: 3]
string_to_handle(str, bindings, opt \\ [])
View Source
string_to_handle(String.t(), binding_struct(), list()) ::
query_handle()
| {:error, :qlc,
{non_neg_integer() | {non_neg_integer(), pos_integer()}, atom(), any()}}
string_to_handle(String.t(), binding_struct(), list()) :: query_handle() | {:error, :qlc, {non_neg_integer() | {non_neg_integer(), pos_integer()}, atom(), any()}}
string to qlc_handle with variable bindings
table(traverse_fun, option \\ [])
View Source
table(traverse_fun(), table_options()) :: query_handle()
table(traverse_fun(), table_options()) :: query_handle()
create qlc handle for any. see :qlc.table/2
example
iex> q = Qlc.table(fn() -> [a: 1, b: 2, c: 3] end, [])
...> Qlc.q("[X || X = {K, V} <- L, K =:= Y]", [L: q, Y: :a]) |>
...> Qlc.e()
[a: 1]
iex> tf = fn(r, f) ->
...> [r.first |
...> fn() ->
...> last = r.last
...> case r.first do
...> x when x < last ->
...> f.(Range.new(r.first+1, last), f)
...> _x -> []
...> end
...> end]
...> end
...> trf = fn(r) -> tf.(r, tf) end
...> q = Qlc.table(fn() -> trf.(1..3) end, [])
...> Qlc.q("[X || X <- Q, X > 2]", [Q: q]) |> Qlc.e()
[3]