poa-netstats-warehouse/doc/POABackend.Receivers.Repo.html

1853 lines
73 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.18.4">
<title>POABackend.Receivers.Repo poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-f62ce50de1.js"></script>
</head>
<body data-type="modules">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
<div class="main">
<button class="sidebar-button sidebar-toggle">
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
<span class="icon-theme" aria-hidden="true"></span>
<span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">
<a href="POABackend.html" class="sidebar-projectLink">
<div class="sidebar-projectDetails">
<h1 class="sidebar-projectName">
poa_backend
</h1>
<h2 class="sidebar-projectVersion">
v0.1.0
</h2>
</div>
</a>
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button">
<span class="icon-search" aria-hidden="true"></span>
</button>
<input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
</form>
<ul class="sidebar-listNav">
<li><a id="extras-list" href="#full-list">Pages</a></li>
<li><a id="modules-list" href="#full-list">Modules</a></li>
</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
</section>
<section class="content">
<div class="content-outer">
<div id="content" class="content-inner">
<h1>
<small class="visible-xs">poa_backend v0.1.0</small>
POABackend.Receivers.Repo
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L1" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</h1>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#aggregate/4">aggregate(queryable, aggregate, field, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Calculate the given <code class="inline">aggregate</code> over the given <code class="inline">field</code></p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#all/2">all(queryable, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Fetches all entries from the data store matching the given query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#config/0">config()</a>
</div>
<div class="summary-synopsis"><p>Returns the adapter configuration stored in the <code class="inline">:otp_app</code> environment</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#delete/2">delete(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Deletes a struct using its primary key</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#delete!/2">delete!(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Same as <a href="#delete/2"><code class="inline">delete/2</code></a> but returns the struct or raises if the changeset is invalid</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#delete_all/2">delete_all(queryable, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Deletes all entries matching the given query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get/3">get(queryable, id, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Fetches a single struct from the data store where the primary key matches the
given id</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get!/3">get!(queryable, id, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Similar to <a href="#get/3"><code class="inline">get/3</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_by/3">get_by(queryable, clauses, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Fetches a single result from the query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_by!/3">get_by!(queryable, clauses, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Similar to <a href="#get_by/3"><code class="inline">get_by/3</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#in_transaction?/0">in_transaction?()</a>
</div>
<div class="summary-synopsis"><p>Returns true if the current process is inside a transaction</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert/2">insert(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Inserts a struct or a changeset</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert!/2">insert!(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Same as <a href="#insert/2"><code class="inline">insert/2</code></a> but returns the struct or raises if the changeset is invalid</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert_all/3">insert_all(schema_or_source, entries, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Inserts all entries into the repository</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert_or_update/2">insert_or_update(changeset, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Inserts or updates a changeset depending on whether the struct is persisted
or not</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert_or_update!/2">insert_or_update!(changeset, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Same as <a href="#insert_or_update/2"><code class="inline">insert_or_update/2</code></a> but returns the struct or raises if the changeset
is invalid</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#load/2">load(schema_or_types, data)</a>
</div>
<div class="summary-synopsis"><p>Loads <code class="inline">data</code> into a struct or a map</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#one/2">one(queryable, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Fetches a single result from the query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#one!/2">one!(queryable, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Similar to <a href="#one/2"><code class="inline">one/2</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#preload/3">preload(struct_or_structs, preloads, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Preloads all associations on the given struct or structs</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#query/3">query(sql, params \\ [], opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>A convenience function for SQL-based repositories that executes the given query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#query!/3">query!(sql, params \\ [], opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>A convenience function for SQL-based repositories that executes the given query</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#rollback/1">rollback(value)</a>
</div>
<div class="summary-synopsis"><p>Rolls back the current transaction</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#start_link/1">start_link(opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Starts any connection pooling or supervision and return <code class="inline">{:ok, pid}</code>
or just <code class="inline">:ok</code> if nothing needs to be done</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#stop/2">stop(pid, timeout \\ 5000)</a>
</div>
<div class="summary-synopsis"><p>Shuts down the repository represented by the given pid</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#stream/2">stream(queryable, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Returns a lazy enumerable that emits all entries from the data store
matching the given query. SQL adapters, such as Postgres and MySQL, can only
enumerate a stream inside a transaction</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#transaction/2">transaction(fun_or_multi, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Runs the given function or <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Multi.html"><code class="inline">Ecto.Multi</code></a> inside a transaction</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#update/2">update(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Updates a changeset using its primary key</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#update!/2">update!(struct, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Same as <a href="#update/2"><code class="inline">update/2</code></a> but returns the struct or raises if the changeset is invalid</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#update_all/3">update_all(queryable, updates, opts \\ [])</a>
</div>
<div class="summary-synopsis"><p>Updates all entries matching the given query with the given values</p>
</div>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Functions
</h1>
<div class="detail" id="aggregate/4">
<span id="aggregate/3"></span>
<div class="detail-header">
<a href="#aggregate/4" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">aggregate(queryable, aggregate, field, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Calculate the given <code class="inline">aggregate</code> over the given <code class="inline">field</code>.</p>
<p>If the query has a limit, offset or distinct set, it will be
automatically wrapped in a subquery in order to return the
proper result.</p>
<p>Any preload or select in the query will be ignored in favor of
the column being aggregated.</p>
<p>The aggregation will fail if any <code class="inline">group_by</code> field is set.</p>
<h2 id="aggregate/4-options" class="section-heading">
<a href="#aggregate/4-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="aggregate/4-examples" class="section-heading">
<a href="#aggregate/4-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir"># Returns the number of visits per blog post
Repo.aggregate(Post, :count, :visits)
# Returns the average number of visits for the top 10
query = from Post, limit: 10
Repo.aggregate(query, :avg, :visits)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:aggregate/4"><code class="inline">Ecto.Repo.aggregate/4</code></a>.</p>
</section>
</div>
<div class="detail" id="all/2">
<span id="all/1"></span>
<div class="detail-header">
<a href="#all/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">all(queryable, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Fetches all entries from the data store matching the given query.</p>
<p>May raise <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.QueryError.html"><code class="inline">Ecto.QueryError</code></a> if query validation fails.</p>
<h2 id="all/2-options" class="section-heading">
<a href="#all/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the query.
</li>
</ul>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="all/2-example" class="section-heading">
<a href="#all/2-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir"># Fetch all post titles
query = from p in Post,
select: p.title
MyRepo.all(query)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:all/2"><code class="inline">Ecto.Repo.all/2</code></a>.</p>
</section>
</div>
<div class="detail" id="config/0">
<div class="detail-header">
<a href="#config/0" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">config()</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Returns the adapter configuration stored in the <code class="inline">:otp_app</code> environment.</p>
<p>Dynamic configuration is not reflected on this value.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:config/0"><code class="inline">Ecto.Repo.config/0</code></a>.</p>
</section>
</div>
<div class="detail" id="delete/2">
<span id="delete/1"></span>
<div class="detail-header">
<a href="#delete/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">delete(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Deletes a struct using its primary key.</p>
<p>If the struct has no primary key, <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoPrimaryKeyFieldError.html"><code class="inline">Ecto.NoPrimaryKeyFieldError</code></a>
will be raised.</p>
<p>It returns <code class="inline">{:ok, struct}</code> if the struct has been successfully
deleted or <code class="inline">{:error, changeset}</code> if there was a validation
or a known constraint error.</p>
<h2 id="delete/2-options" class="section-heading">
<a href="#delete/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the struct.
</li>
</ul>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="delete/2-example" class="section-heading">
<a href="#delete/2-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">post = MyRepo.get!(Post, 42)
case MyRepo.delete post do
{:ok, struct} -&gt; # Deleted with success
{:error, changeset} -&gt; # Something went wrong
end</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:delete/2"><code class="inline">Ecto.Repo.delete/2</code></a>.</p>
</section>
</div>
<div class="detail" id="delete!/2">
<span id="delete!/1"></span>
<div class="detail-header">
<a href="#delete!/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">delete!(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Same as <a href="#delete/2"><code class="inline">delete/2</code></a> but returns the struct or raises if the changeset is invalid.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:delete!/2"><code class="inline">Ecto.Repo.delete!/2</code></a>.</p>
</section>
</div>
<div class="detail" id="delete_all/2">
<span id="delete_all/1"></span>
<div class="detail-header">
<a href="#delete_all/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">delete_all(queryable, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Deletes all entries matching the given query.</p>
<p>It returns a tuple containing the number of entries
and any returned result as second element. If the database
does not support RETURNING in DELETE statements or no
return result was selected, the second element will be <code class="inline">nil</code>.</p>
<h2 id="delete_all/2-options" class="section-heading">
<a href="#delete_all/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:returning</code> - selects which fields to return. When <code class="inline">true</code>,
returns all fields in the given struct. May be a list of
fields, where a struct is still returned but only with the
given fields. Or <code class="inline">false</code>, where nothing is returned (the default).
This option is not supported by all databases.
</li>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the query.
</li>
</ul>
<p>See the “Shared options” section at the module documentation for
remaining options.</p>
<h2 id="delete_all/2-examples" class="section-heading">
<a href="#delete_all/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">MyRepo.delete_all(Post)
from(p in Post, where: p.id &lt; 10) |&gt; MyRepo.delete_all</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:delete_all/2"><code class="inline">Ecto.Repo.delete_all/2</code></a>.</p>
</section>
</div>
<div class="detail" id="get/3">
<span id="get/2"></span>
<div class="detail-header">
<a href="#get/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get(queryable, id, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Fetches a single struct from the data store where the primary key matches the
given id.</p>
<p>Returns <code class="inline">nil</code> if no result was found. If the struct in the queryable
has no or more than one primary key, it will raise an argument error.</p>
<h2 id="get/3-options" class="section-heading">
<a href="#get/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="get/3-example" class="section-heading">
<a href="#get/3-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">MyRepo.get(Post, 42)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:get/3"><code class="inline">Ecto.Repo.get/3</code></a>.</p>
</section>
</div>
<div class="detail" id="get!/3">
<span id="get!/2"></span>
<div class="detail-header">
<a href="#get!/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get!(queryable, id, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Similar to <a href="#get/3"><code class="inline">get/3</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found.</p>
<h2 id="get!/3-options" class="section-heading">
<a href="#get!/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="get!/3-example" class="section-heading">
<a href="#get!/3-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">MyRepo.get!(Post, 42)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:get!/3"><code class="inline">Ecto.Repo.get!/3</code></a>.</p>
</section>
</div>
<div class="detail" id="get_by/3">
<span id="get_by/2"></span>
<div class="detail-header">
<a href="#get_by/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get_by(queryable, clauses, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Fetches a single result from the query.</p>
<p>Returns <code class="inline">nil</code> if no result was found.</p>
<h2 id="get_by/3-options" class="section-heading">
<a href="#get_by/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="get_by/3-example" class="section-heading">
<a href="#get_by/3-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">MyRepo.get_by(Post, title: &quot;My post&quot;)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:get_by/3"><code class="inline">Ecto.Repo.get_by/3</code></a>.</p>
</section>
</div>
<div class="detail" id="get_by!/3">
<span id="get_by!/2"></span>
<div class="detail-header">
<a href="#get_by!/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get_by!(queryable, clauses, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Similar to <a href="#get_by/3"><code class="inline">get_by/3</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found.</p>
<h2 id="get_by!/3-options" class="section-heading">
<a href="#get_by!/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="get_by!/3-example" class="section-heading">
<a href="#get_by!/3-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">MyRepo.get_by!(Post, title: &quot;My post&quot;)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:get_by!/3"><code class="inline">Ecto.Repo.get_by!/3</code></a>.</p>
</section>
</div>
<div class="detail" id="in_transaction?/0">
<div class="detail-header">
<a href="#in_transaction?/0" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">in_transaction?()</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Returns true if the current process is inside a transaction.</p>
<h2 id="in_transaction?/0-examples" class="section-heading">
<a href="#in_transaction?/0-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">MyRepo.in_transaction?
#=&gt; false
MyRepo.transaction(fn -&gt;
MyRepo.in_transaction? #=&gt; true
end)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:in_transaction?/0"><code class="inline">Ecto.Repo.in_transaction?/0</code></a>.</p>
</section>
</div>
<div class="detail" id="insert/2">
<span id="insert/1"></span>
<div class="detail-header">
<a href="#insert/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Inserts a struct or a changeset.</p>
<p>In case a struct is given, the struct is converted into a changeset
with all non-nil fields as part of the changeset.</p>
<p>In case a changeset is given, the changes in the changeset are
merged with the struct fields, and all of them are sent to the
database.</p>
<p>It returns <code class="inline">{:ok, struct}</code> if the struct has been successfully
inserted or <code class="inline">{:error, changeset}</code> if there was a validation
or a known constraint error.</p>
<h2 id="insert/2-options" class="section-heading">
<a href="#insert/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the struct.
</li>
<li><code class="inline">:on_conflict</code> - It may be one of <code class="inline">:raise</code> (the default), <code class="inline">:nothing</code>,
<code class="inline">:replace_all</code>, a keyword list of update instructions or an <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html"><code class="inline">Ecto.Query</code></a>
query for updates. See the “Upserts” section for more information.
</li>
<li><code class="inline">:conflict_target</code> - Which columns to verify for conflicts. If
none is specified, the conflict target is left up to the database
and is usually made of primary keys and/or unique/exclusion constraints.
</li>
</ul>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="insert/2-examples" class="section-heading">
<a href="#insert/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<p>A typical example is calling <code class="inline">MyRepo.insert/1</code> with a struct
and acting on the return value:</p>
<pre><code class="elixir">case MyRepo.insert %Post{title: &quot;Ecto is great&quot;} do
{:ok, struct} -&gt; # Inserted with success
{:error, changeset} -&gt; # Something went wrong
end</code></pre>
<h2 id="insert/2-upserts" class="section-heading">
<a href="#insert/2-upserts" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Upserts
</h2>
<p><code class="inline">insert_all</code> provides upserts (update or inserts) via the <code class="inline">:on_conflict</code>
option. The <code class="inline">:on_conflict</code> option supports the following values:</p>
<ul>
<li><code class="inline">:raise</code> - raises if there is a conflicting primary key or unique index
</li>
<li><code class="inline">:nothing</code> - ignores the error in case of conflicts
</li>
<li><code class="inline">:replace_all</code> - replace all entries in the database by the one being
currently attempted
</li>
<li>a keyword list of update instructions - such as the one given to
<code class="inline">c:update_all/3</code>, for example: <code class="inline">[set: [title: &quot;new title&quot;]]</code>
</li>
<li>an <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html"><code class="inline">Ecto.Query</code></a> that will act as an <code class="inline">UPDATE</code> statement, such as the
one given to <code class="inline">c:update_all/3</code>
</li>
</ul>
<p>Upserts map to “ON CONFLICT” on databases like Postgres and “ON DUPLICATE KEY”
on databases such as MySQL.</p>
<p>As an example, imagine <code class="inline">:title</code> is marked as a unique column in
the database:</p>
<pre><code class="elixir"># Insert it once
{:ok, inserted} = MyRepo.insert(%Post{title: &quot;this is unique&quot;})
# Insert with the same title but do nothing on conflicts.
# Keep in mind that, although this returns :ok, the returned
# struct does not reflect the data in the database. For instance,
# in case of &quot;on_conflict: :nothing&quot;, the returned post has no ID.
{:ok, ignored} = MyRepo.insert(%Post{title: &quot;this is unique&quot;}, on_conflict: :nothing)
assert ignored.id == nil
# Now let&#39;s insert with the same title but use a query to update
# a column on conflicts. Although this returns :ok and a struct with
# the existing ID for successful operations, the other columns may
# not necessarily reflect the data in the database. In fact, any
# operation done on `:on_conflict` won&#39;t be automatically mapped to
# the struct.
# In Postgres (it requires the conflict target for updates):
on_conflict = [set: [body: &quot;updated&quot;]]
{:ok, updated} = MyRepo.insert(%Post{title: &quot;this is unique&quot;},
on_conflict: on_conflict, conflict_target: :title)
# In MySQL (conflict target is not supported):
on_conflict = [set: [title: &quot;updated&quot;]]
{:ok, updated} = MyRepo.insert(%Post{id: inserted.id, title: &quot;updated&quot;},
on_conflict: on_conflict)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:insert/2"><code class="inline">Ecto.Repo.insert/2</code></a>.</p>
</section>
</div>
<div class="detail" id="insert!/2">
<span id="insert!/1"></span>
<div class="detail-header">
<a href="#insert!/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert!(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Same as <a href="#insert/2"><code class="inline">insert/2</code></a> but returns the struct or raises if the changeset is invalid.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:insert!/2"><code class="inline">Ecto.Repo.insert!/2</code></a>.</p>
</section>
</div>
<div class="detail" id="insert_all/3">
<span id="insert_all/2"></span>
<div class="detail-header">
<a href="#insert_all/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert_all(schema_or_source, entries, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Inserts all entries into the repository.</p>
<p>It expects a schema (<code class="inline">MyApp.User</code>) or a source (<code class="inline">&quot;users&quot;</code>) or
both (<code class="inline">{&quot;users&quot;, MyApp.User}</code>) as the first argument. The second
argument is a list of entries to be inserted, either as keyword
lists or as maps.</p>
<p>It returns a tuple containing the number of entries
and any returned result as second element. If the database
does not support RETURNING in UPDATE statements or no
return result was selected, the second element will be <code class="inline">nil</code>.</p>
<p>When a schema is given, the values given will be properly dumped
before being sent to the database. If the schema contains an
autogenerated ID field, it will be handled either at the adapter
or the storage layer. However any other autogenerated value, like
timestamps, wont be autogenerated when using <code class="inline">c:insert_all/3</code>.
This is by design as this function aims to be a more direct way
to insert data into the database without the conveniences of
<code class="inline">c:insert/2</code>. This is also consistent with <code class="inline">c:update_all/3</code> that
does not handle timestamps as well.</p>
<p>If a source is given, without a schema, the given fields are passed
as is to the adapter.</p>
<h2 id="insert_all/3-options" class="section-heading">
<a href="#insert_all/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:returning</code> - selects which fields to return. When <code class="inline">true</code>,
returns all fields in the given struct. May be a list of
fields, where a struct is still returned but only with the
given fields. Or <code class="inline">false</code>, where nothing is returned (the default).
This option is not supported by all databases.
</li>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL).
</li>
<li><code class="inline">:on_conflict</code> - It may be one of <code class="inline">:raise</code> (the default), <code class="inline">:nothing</code>,
<code class="inline">:replace_all</code>, a keyword list of update instructions or an <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html"><code class="inline">Ecto.Query</code></a>
query for updates. See the “Upserts” section for more information.
</li>
<li><code class="inline">:conflict_target</code> - Which columns to verify for conflicts. If
none is specified, the conflict target is left up to the database
and is usually made of primary keys and/or unique/exclusion constraints.
</li>
</ul>
<p>See the “Shared options” section at the module documentation for
remaining options.</p>
<h2 id="insert_all/3-examples" class="section-heading">
<a href="#insert_all/3-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">MyRepo.insert_all(Post, [[title: &quot;My first post&quot;], [title: &quot;My second post&quot;]])
MyRepo.insert_all(Post, [%{title: &quot;My first post&quot;}, %{title: &quot;My second post&quot;}])</code></pre>
<h2 id="insert_all/3-upserts" class="section-heading">
<a href="#insert_all/3-upserts" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Upserts
</h2>
<p><code class="inline">insert_all</code> provides upserts (update or inserts) via the <code class="inline">:on_conflict</code>
option. The <code class="inline">:on_conflict</code> option supports the following values:</p>
<ul>
<li><code class="inline">:raise</code> - raises if there is a conflicting primary key or unique index
</li>
<li><code class="inline">:nothing</code> - ignores the error in case of conflicts
</li>
<li><code class="inline">:replace_all</code> - replace all entries in the database by the one being
currently attempted
</li>
<li>a keyword list of update instructions - such as the one given to
<code class="inline">c:update_all/3</code>, for example: <code class="inline">[set: [title: &quot;new title&quot;]]</code>
</li>
<li>an <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html"><code class="inline">Ecto.Query</code></a> that will act as an <code class="inline">UPDATE</code> statement, such as the
one given to <code class="inline">c:update_all/3</code>
</li>
</ul>
<p>Upserts map to “ON CONFLICT” on databases like Postgres and “ON DUPLICATE KEY”
on databases such as MySQL.</p>
<h2 id="insert_all/3-return-values" class="section-heading">
<a href="#insert_all/3-return-values" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Return values
</h2>
<p>By default, both Postgres and MySQL return the amount of entries
inserted on <code class="inline">insert_all</code>. However, when the <code class="inline">:on_conflict</code> option
is specified, Postgres will only return a row if it was affected
while MySQL returns at least the number of entries attempted.</p>
<p>For example, if <code class="inline">:on_conflict</code> is set to <code class="inline">:nothing</code>, Postgres will
return 0 if no new entry was added while MySQL will still return
the amount of entries attempted to be inserted, even if no entry
was added. Even worse, if <code class="inline">:on_conflict</code> is query, MySQL will return
the number of attempted entries plus the number of entries modified
by the UPDATE query.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:insert_all/3"><code class="inline">Ecto.Repo.insert_all/3</code></a>.</p>
</section>
</div>
<div class="detail" id="insert_or_update/2">
<span id="insert_or_update/1"></span>
<div class="detail-header">
<a href="#insert_or_update/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert_or_update(changeset, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Inserts or updates a changeset depending on whether the struct is persisted
or not.</p>
<p>The distinction whether to insert or update will be made on the
<a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Schema.Metadata.html"><code class="inline">Ecto.Schema.Metadata</code></a> field <code class="inline">:state</code>. The <code class="inline">:state</code> is automatically set by
Ecto when loading or building a schema.</p>
<p>Please note that for this to work, you will have to load existing structs from
the database. So even if the struct exists, this wont work:</p>
<pre><code class="elixir">struct = %Post{id: &#39;existing_id&#39;, ...}
MyRepo.insert_or_update changeset
# =&gt; {:error, &quot;id already exists&quot;}</code></pre>
<h2 id="insert_or_update/2-options" class="section-heading">
<a href="#insert_or_update/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the struct.
</li>
</ul>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="insert_or_update/2-example" class="section-heading">
<a href="#insert_or_update/2-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">result =
case MyRepo.get(Post, id) do
nil -&gt; %Post{id: id} # Post not found, we build one
post -&gt; post # Post exists, let&#39;s use it
end
|&gt; Post.changeset(changes)
|&gt; MyRepo.insert_or_update
case result do
{:ok, struct} -&gt; # Inserted or updated with success
{:error, changeset} -&gt; # Something went wrong
end</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:insert_or_update/2"><code class="inline">Ecto.Repo.insert_or_update/2</code></a>.</p>
</section>
</div>
<div class="detail" id="insert_or_update!/2">
<span id="insert_or_update!/1"></span>
<div class="detail-header">
<a href="#insert_or_update!/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert_or_update!(changeset, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Same as <a href="#insert_or_update/2"><code class="inline">insert_or_update/2</code></a> but returns the struct or raises if the changeset
is invalid.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:insert_or_update!/2"><code class="inline">Ecto.Repo.insert_or_update!/2</code></a>.</p>
</section>
</div>
<div class="detail" id="load/2">
<div class="detail-header">
<a href="#load/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">load(schema_or_types, data)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Loads <code class="inline">data</code> into a struct or a map.</p>
<p>The first argument can be a schema, or a map (of types) and determines the return value:
a struct or a map, respectively.</p>
<p>The second argument <code class="inline">data</code> specifies fields and values that are to be loaded.
It can be a map, a keyword list, or a <code class="inline">{fields, values}</code> tuple.
Fields can be atoms or strings.</p>
<p>Fields that are not present in the schema (or <code class="inline">types</code> map) are ignored.
If any of the values has invalid type, an error is raised.</p>
<h2 id="load/2-examples" class="section-heading">
<a href="#load/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="iex elixir">iex&gt; MyRepo.load(User, %{name: &quot;Alice&quot;, age: 25})
%User{name: &quot;Alice&quot;, age: 25}
iex&gt; MyRepo.load(User, [name: &quot;Alice&quot;, age: 25])
%User{name: &quot;Alice&quot;, age: 25}</code></pre>
<p><code class="inline">data</code> can also take form of <code class="inline">{fields, values}</code>:</p>
<pre><code class="iex elixir">iex&gt; MyRepo.load(User, {[:name, :age], [&quot;Alice&quot;, 25]})
%User{name: &quot;Alice&quot;, age: 25, ...}</code></pre>
<p>The first argument can also be a <code class="inline">types</code> map:</p>
<pre><code class="iex elixir">iex&gt; types = %{name: :string, age: :integer}
iex&gt; MyRepo.load(types, %{name: &quot;Alice&quot;, age: 25})
%{name: &quot;Alice&quot;, age: 25}</code></pre>
<p>This function is especially useful when parsing raw query results:</p>
<pre><code class="iex elixir">iex&gt; result = Ecto.Adapters.SQL.query!(MyRepo, &quot;SELECT * FROM users&quot;, [])
iex&gt; Enum.map(result.rows, &amp;MyRepo.load(User, {result.columns, &amp;1}))
[%User{...}, ...]</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:load/2"><code class="inline">Ecto.Repo.load/2</code></a>.</p>
</section>
</div>
<div class="detail" id="one/2">
<span id="one/1"></span>
<div class="detail-header">
<a href="#one/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">one(queryable, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Fetches a single result from the query.</p>
<p>Returns <code class="inline">nil</code> if no result was found. Raises if more than one entry.</p>
<h2 id="one/2-options" class="section-heading">
<a href="#one/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:one/2"><code class="inline">Ecto.Repo.one/2</code></a>.</p>
</section>
</div>
<div class="detail" id="one!/2">
<span id="one!/1"></span>
<div class="detail-header">
<a href="#one!/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">one!(queryable, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Similar to <a href="#one/2"><code class="inline">one/2</code></a> but raises <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoResultsError.html"><code class="inline">Ecto.NoResultsError</code></a> if no record was found.</p>
<p>Raises if more than one entry.</p>
<h2 id="one!/2-options" class="section-heading">
<a href="#one!/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:one!/2"><code class="inline">Ecto.Repo.one!/2</code></a>.</p>
</section>
</div>
<div class="detail" id="preload/3">
<span id="preload/2"></span>
<div class="detail-header">
<a href="#preload/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">preload(struct_or_structs, preloads, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Preloads all associations on the given struct or structs.</p>
<p>This is similar to <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html#preload/3"><code class="inline">Ecto.Query.preload/3</code></a> except it allows
you to preload structs after they have been fetched from the
database.</p>
<p>In case the association was already loaded, preload wont attempt
to reload it.</p>
<h2 id="preload/3-options" class="section-heading">
<a href="#preload/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>Besides the “Shared options” section at the module documentation,
it accepts:</p>
<ul>
<li><code class="inline">:force</code> - By default, Ecto wont preload associations that
are already loaded. By setting this option to true, any existing
association will be discarded and reloaded.
</li>
<li><code class="inline">:in_parallel</code> - If the preloads must be done in parallel. It can
only be performed when we have more than one preload and the
repository is not in a transaction. Defaults to <code class="inline">true</code>.
</li>
<li><code class="inline">:prefix</code> - the prefix to fetch preloads from. By default, queries
will use the same prefix as the one in the given collection. This
option allows the prefix to be changed.
</li>
</ul>
<h2 id="preload/3-examples" class="section-heading">
<a href="#preload/3-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">posts = Repo.preload posts, :comments
posts = Repo.preload posts, comments: :permalinks
posts = Repo.preload posts, comments: from(c in Comment, order_by: c.published_at)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:preload/3"><code class="inline">Ecto.Repo.preload/3</code></a>.</p>
</section>
</div>
<div class="detail" id="query/3">
<span id="query/1"></span>
<span id="query/2"></span>
<div class="detail-header">
<a href="#query/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">query(sql, params \\ [], opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L1" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>A convenience function for SQL-based repositories that executes the given query.</p>
<p>See <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Adapters.SQL.html#query/3"><code class="inline">Ecto.Adapters.SQL.query/3</code></a> for more information.</p>
</section>
</div>
<div class="detail" id="query!/3">
<span id="query!/1"></span>
<span id="query!/2"></span>
<div class="detail-header">
<a href="#query!/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">query!(sql, params \\ [], opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L1" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>A convenience function for SQL-based repositories that executes the given query.</p>
<p>See <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Adapters.SQL.html#query/3"><code class="inline">Ecto.Adapters.SQL.query/3</code></a> for more information.</p>
</section>
</div>
<div class="detail" id="rollback/1">
<div class="detail-header">
<a href="#rollback/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">rollback(value)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>rollback(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>()) :: <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">no_return</a>()</pre>
</div>
</div>
<section class="docstring">
<p>Rolls back the current transaction.</p>
<p>The transaction will return the value given as <code class="inline">{:error, value}</code>.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:rollback/1"><code class="inline">Ecto.Repo.rollback/1</code></a>.</p>
</section>
</div>
<div class="detail" id="start_link/1">
<span id="start_link/0"></span>
<div class="detail-header">
<a href="#start_link/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">start_link(opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Starts any connection pooling or supervision and return <code class="inline">{:ok, pid}</code>
or just <code class="inline">:ok</code> if nothing needs to be done.</p>
<p>Returns <code class="inline">{:error, {:already_started, pid}}</code> if the repo is already
started or <code class="inline">{:error, term}</code> in case anything else goes wrong.</p>
<h2 id="start_link/1-options" class="section-heading">
<a href="#start_link/1-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the configuration in the moduledoc for options shared between adapters,
for adapter-specific configuration see the adapters documentation.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:start_link/1"><code class="inline">Ecto.Repo.start_link/1</code></a>.</p>
</section>
</div>
<div class="detail" id="stop/2">
<span id="stop/1"></span>
<div class="detail-header">
<a href="#stop/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">stop(pid, timeout \\ 5000)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Shuts down the repository represented by the given pid.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:stop/2"><code class="inline">Ecto.Repo.stop/2</code></a>.</p>
</section>
</div>
<div class="detail" id="stream/2">
<span id="stream/1"></span>
<div class="detail-header">
<a href="#stream/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">stream(queryable, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Returns a lazy enumerable that emits all entries from the data store
matching the given query. SQL adapters, such as Postgres and MySQL, can only
enumerate a stream inside a transaction.</p>
<p>May raise <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.QueryError.html"><code class="inline">Ecto.QueryError</code></a> if query validation fails.</p>
<h2 id="stream/2-options" class="section-heading">
<a href="#stream/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><p><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the query</p>
</li>
<li><p><code class="inline">:max_rows</code> - The number of rows to load from the database as we stream.
It is supported at least by Postgres and MySQL and defaults to 500.</p>
</li>
</ul>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="stream/2-example" class="section-heading">
<a href="#stream/2-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir"># Fetch all post titles
query = from p in Post,
select: p.title
stream = MyRepo.stream(query)
MyRepo.transaction(fn() -&gt;
Enum.to_list(stream)
end)</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:stream/2"><code class="inline">Ecto.Repo.stream/2</code></a>.</p>
</section>
</div>
<div class="detail" id="transaction/2">
<span id="transaction/1"></span>
<div class="detail-header">
<a href="#transaction/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">transaction(fun_or_multi, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Runs the given function or <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Multi.html"><code class="inline">Ecto.Multi</code></a> inside a transaction.</p>
<h2 id="transaction/2-use-with-function" class="section-heading">
<a href="#transaction/2-use-with-function" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Use with function
</h2>
<p>If an unhandled error occurs the transaction will be rolled back
and the error will bubble up from the transaction function.
If no error occurred the transaction will be committed when the
function returns. A transaction can be explicitly rolled back
by calling <a href="#rollback/1"><code class="inline">rollback/1</code></a>, this will immediately leave the function
and return the value given to <code class="inline">rollback</code> as <code class="inline">{:error, value}</code>.</p>
<p>A successful transaction returns the value returned by the function
wrapped in a tuple as <code class="inline">{:ok, value}</code>.</p>
<p>If <a href="#transaction/2"><code class="inline">transaction/2</code></a> is called inside another transaction, the function
is simply executed, without wrapping the new transaction call in any
way. If there is an error in the inner transaction and the error is
rescued, or the inner transaction is rolled back, the whole outer
transaction is marked as tainted, guaranteeing nothing will be committed.</p>
<h2 id="transaction/2-use-with-ecto-multi" class="section-heading">
<a href="#transaction/2-use-with-ecto-multi" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Use with Ecto.Multi
</h2>
<p>Besides functions transaction can be used with an Ecto.Multi struct.
Transaction will be started, all operations applied and in case of
success committed returning <code class="inline">{:ok, changes}</code>. In case of any errors
the transaction will be rolled back and
<code class="inline">{:error, failed_operation, failed_value, changes_so_far}</code> will be
returned.</p>
<p>You can read more about using transactions with <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Multi.html"><code class="inline">Ecto.Multi</code></a> as well as
see some examples in the <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Multi.html"><code class="inline">Ecto.Multi</code></a> documentation.</p>
<h2 id="transaction/2-options" class="section-heading">
<a href="#transaction/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>See the “Shared options” section at the module documentation.</p>
<h2 id="transaction/2-examples" class="section-heading">
<a href="#transaction/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">MyRepo.transaction(fn -&gt;
MyRepo.update!(%{alice | balance: alice.balance - 10})
MyRepo.update!(%{bob | balance: bob.balance + 10})
end)
# Roll back a transaction explicitly
MyRepo.transaction(fn -&gt;
p = MyRepo.insert!(%Post{})
if not Editor.post_allowed?(p) do
MyRepo.rollback(:posting_not_allowed)
end
end)
# With Ecto.Multi
Ecto.Multi.new
|&gt; Ecto.Multi.insert(:post, %Post{})
|&gt; MyRepo.transaction</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:transaction/2"><code class="inline">Ecto.Repo.transaction/2</code></a>.</p>
</section>
</div>
<div class="detail" id="update/2">
<span id="update/1"></span>
<div class="detail-header">
<a href="#update/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">update(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Updates a changeset using its primary key.</p>
<p>A changeset is required as it is the only mechanism for
tracking dirty changes. Only the fields present in the <code class="inline">changes</code> part
of the changeset are sent to the database. Any other, in-memory
changes done to the schema are ignored.</p>
<p>If the struct has no primary key, <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.NoPrimaryKeyFieldError.html"><code class="inline">Ecto.NoPrimaryKeyFieldError</code></a>
will be raised.</p>
<p>It returns <code class="inline">{:ok, struct}</code> if the struct has been successfully
updated or <code class="inline">{:error, changeset}</code> if there was a validation
or a known constraint error.</p>
<h2 id="update/2-options" class="section-heading">
<a href="#update/2-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<p>Besides the “Shared options” section at the module documentation,
it accepts:</p>
<ul>
<li><code class="inline">:force</code> - By default, if there are no changes in the changeset,
<a href="#update!/2"><code class="inline">update!/2</code></a> is a no-op. By setting this option to true, update
callbacks will always be executed, even if there are no changes
(including timestamps).
</li>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the struct.
</li>
</ul>
<h2 id="update/2-example" class="section-heading">
<a href="#update/2-example" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Example
</h2>
<pre><code class="elixir">post = MyRepo.get!(Post, 42)
post = Ecto.Changeset.change post, title: &quot;New title&quot;
case MyRepo.update post do
{:ok, struct} -&gt; # Updated with success
{:error, changeset} -&gt; # Something went wrong
end</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:update/2"><code class="inline">Ecto.Repo.update/2</code></a>.</p>
</section>
</div>
<div class="detail" id="update!/2">
<span id="update!/1"></span>
<div class="detail-header">
<a href="#update!/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">update!(struct, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Same as <a href="#update/2"><code class="inline">update/2</code></a> but returns the struct or raises if the changeset is invalid.</p>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:update!/2"><code class="inline">Ecto.Repo.update!/2</code></a>.</p>
</section>
</div>
<div class="detail" id="update_all/3">
<span id="update_all/2"></span>
<div class="detail-header">
<a href="#update_all/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">update_all(queryable, updates, opts \\ [])</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/repo.ex#L2" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p>Updates all entries matching the given query with the given values.</p>
<p>It returns a tuple containing the number of entries
and any returned result as second element. If the database
does not support RETURNING in UPDATE statements or no
return result was selected, the second element will be <code class="inline">nil</code>.</p>
<p>Keep in mind this <code class="inline">update_all</code> will not update autogenerated
fields like the <code class="inline">updated_at</code> columns.</p>
<p>See <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Query.html#update/3"><code class="inline">Ecto.Query.update/3</code></a> for update operations that can be
performed on fields.</p>
<h2 id="update_all/3-options" class="section-heading">
<a href="#update_all/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Options
</h2>
<ul>
<li><code class="inline">:returning</code> - selects which fields to return. When <code class="inline">true</code>,
returns all fields in the given struct. May be a list of
fields, where a struct is still returned but only with the
given fields. Or <code class="inline">false</code>, where nothing is returned (the default).
This option is not supported by all databases.
</li>
<li><code class="inline">:prefix</code> - The prefix to run the query on (such as the schema path
in Postgres or the database in MySQL). This overrides the prefix set
in the query.
</li>
</ul>
<p>See the “Shared options” section at the module documentation for
remaining options.</p>
<h2 id="update_all/3-examples" class="section-heading">
<a href="#update_all/3-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Examples
</h2>
<pre><code class="elixir">MyRepo.update_all(Post, set: [title: &quot;New title&quot;])
MyRepo.update_all(Post, inc: [visits: 1])
from(p in Post, where: p.id &lt; 10)
|&gt; MyRepo.update_all(set: [title: &quot;New title&quot;])
from(p in Post, where: p.id &lt; 10, update: [set: [title: &quot;New title&quot;]])
|&gt; MyRepo.update_all([])
from(p in Post, where: p.id &lt; 10, update: [set: [title: fragment(&quot;?&quot;, new_title)]])
|&gt; MyRepo.update_all([])</code></pre>
<p>Callback implementation for <a href="https://hexdocs.pm/ecto/2.1.6/Ecto.Repo.html#c:update_all/3"><code class="inline">Ecto.Repo.update_all/3</code></a>.</p>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.18.4),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-9bd040e5e5.js"></script>
</body>
</html>