Archeometer.Repo.Result (Archeometer v0.5.0)

A query result with a nicer API to manipulate the data.

Link to this section Summary

Functions

Merges two query results into one using a common column to pair the results values. Rows from second result are dumped into first one.

Link to this section Functions

Link to this function

merge(result1, result2, joiner, default \\ nil)

Merges two query results into one using a common column to pair the results values. Rows from second result are dumped into first one.

examples

Examples

iex> result1 = 
...>   %Archeometer.Repo.Result{
...>     headers: [:id, :name], rows: [[1, "archeometer"]]}
...>
iex> result2 = 
...>   %Archeometer.Repo.Result{
...>     headers: [:name, :num_mods], rows: [["archeometer", 120]]}
...>
iex> Archeometer.Repo.Result.merge(result1, result2, :name)
%Archeometer.Repo.Result{
  headers: [:id, :name, :num_mods],
  rows: [[1, "archeometer", 120]]
}

Trying to merge without a common column

iex> result1 = 
...>   %Archeometer.Repo.Result{
...>     headers: [:id, :is_external], rows: [[1, false]]}
...>
iex> result2 = 
...>   %Archeometer.Repo.Result{
...>     headers: [:name, :num_mods], rows: [["archeometer", 120]]}
...>
iex> Archeometer.Repo.Result.merge(result1, result2, :name)
{:error, "name is not a common column"}