Sorcery.ReturnedEntities (sorcery v0.4.4)
This is the return type of any forward query, and any generated data.
Try not to access the data directly, but rather use the functions in this module.
The reason is that Sorcery is still a work in progress, the format might change, but the functions should never break their contract's.
This is also the basic format of portals.
Currently the :primary_entities field is not being used. The idea was for it to help with ergonomics when a query is only expected to have one result.
Summary
Functions
Takes the :find key from some SrcQL and uses that to prune the RE.
Deletes attribute keys from every entity of the given tk
Removes all the listed ids of a given tk.
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> get_entities(re, :player)
[ %{id: 1, name: "A"}, %{id: 23, name: "B"} ]
Creates a new, empty RE struct.
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "A"}, 23 => %{id: 23, name: "B"}}
iex> re = put_entities(re, :player, [ %{id: 1, name: "C"}, %{id: 42, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "C"}, 23 => %{id: 23, name: "B"}, 42 => %{id: 42, name: "B"}}
Functions
apply_find_map(re, find)
Takes the :find key from some SrcQL and uses that to prune the RE.
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :bird, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> re = put_entities(re, :spell, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> get_entities(re, :bird)
[ %{id: 1, name: "A"}, %{id: 23, name: "B"} ]
iex> re = apply_find_map(re, %{bird: [:id]})
iex> get_entities(re, :bird)
[ %{id: 1}, %{id: 23} ]
assign_lvar_tk(re, lvar, tk)
delete_attrs(re, tk, li)
Deletes attribute keys from every entity of the given tk
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "A"}, 23 => %{id: 23, name: "B"}}
iex> re = delete_attrs(re, :player, [ :name ])
iex> re.data.player
%{1 => %{id: 1}, 23 => %{id: 23}}
delete_entities(re, tk, li)
Removes all the listed ids of a given tk.
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "A"}, 23 => %{id: 23, name: "B"}}
iex> re = delete_entities(re, :player, [ 23 ])
iex> re.data.player
%{1 => %{id: 1, name: "A"}}
get_entities(re, tk)
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> get_entities(re, :player)
[ %{id: 1, name: "A"}, %{id: 23, name: "B"} ]
merge(li)
new()
Creates a new, empty RE struct.
Examples
iex> new()
%Sorcery.ReturnedEntities{ primary_entities: [], data: %{} }
put_entities(re, tk, li)
Examples
iex> re = Sorcery.ReturnedEntities.new()
iex> re = put_entities(re, :player, [ %{id: 1, name: "A"}, %{id: 23, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "A"}, 23 => %{id: 23, name: "B"}}
iex> re = put_entities(re, :player, [ %{id: 1, name: "C"}, %{id: 42, name: "B"}])
iex> re.data.player
%{1 => %{id: 1, name: "C"}, 23 => %{id: 23, name: "B"}, 42 => %{id: 42, name: "B"}}