Bonfire.Common.ReadOnlyRepo (Bonfire v1.0.0-social-rc.2.1)

View Source
An `Ecto.Repo` with no insert/update/delete functions defined

Summary

Functions

Callback implementation for Ecto.Repo.all/2.

Callback implementation for Ecto.Repo.checked_out?/0.

Callback implementation for Ecto.Repo.checkout/2.

Callback implementation for Ecto.Repo.config/0.

A convenience function for SQL-based repositories that forces all connections in the pool to disconnect within the given interval.

A convenience function for SQL-based repositories that executes an EXPLAIN statement or similar depending on the adapter to obtain statistics for the given query.

Execute a query for one result where the primary key matches the given id, and return either an {:ok, result} tuple or a {:error, :not_found}.

Execute a query for multiple results given one or multiple IDs.

Execute a query for one result (using a keyword list to specify the key/value to query with), and return either an {:ok, result} tuple or a {:error, :not_found}.

Like single/1, except on failure, adds an error to the changeset.

Callback implementation for Ecto.Repo.get/3.

Callback implementation for Ecto.Repo.get!/3.

Callback implementation for Ecto.Repo.get_dynamic_repo/0.

Callback implementation for Ecto.Repo.in_transaction?/0.

Callback implementation for Ecto.Repo.load/2.

Execute a query for multiple results and return the results.

Execute a query for multiple results and return one page of results. This uses the main implementation for pagination, which is cursor-based and powered by the Paginator library.

Execute a query for one result and return either a result or a fallback value (nil by default).

Add an ilike clause to a query if the user query is safe.

Callback implementation for Ecto.Repo.one/2.

Callback implementation for Ecto.Repo.one!/2.

Different implementation for pagination using Scrivener (used by eg. rauversion).

Select and return only specific fields (specified as an atom or list of atoms)

A convenience function for SQL-based repositories that executes the given query.

A convenience function for SQL-based repositories that executes the given query.

A convenience function for SQL-based repositories that executes the given multi-result query.

A convenience function for SQL-based repositories that executes the given multi-result query.

Callback implementation for Ecto.Repo.reload/2.

Callback implementation for Ecto.Repo.rollback/1.

Execute a query for one result and return either an {:ok, result} or {:error, :not_found} tuple.

Executes raw SQL query.

Callback implementation for Ecto.Repo.start_link/1.

Callback implementation for Ecto.Repo.stop/1.

Callback implementation for Ecto.Repo.stream/2.

A convenience function for SQL-based repositories that translates the given query to SQL.

Can be used to log specific queries (by calling function) in production.

Run a transaction, similar to Repo.transaction/1, but it expects an ok or error tuple. If an error tuple is returned, the transaction is aborted.

Functions

aggregate(queryable, aggregate, opts \\ [])

Callback implementation for Ecto.Repo.aggregate/3.

aggregate(queryable, aggregate, field, opts)

Callback implementation for Ecto.Repo.aggregate/4.

all(queryable, opts \\ [])

Callback implementation for Ecto.Repo.all/2.

all_by(queryable, clauses, opts \\ [])

Callback implementation for Ecto.Repo.all_by/3.

checked_out?()

Callback implementation for Ecto.Repo.checked_out?/0.

checkout(fun, opts \\ [])

Callback implementation for Ecto.Repo.checkout/2.

child_spec(opts)

config()

Callback implementation for Ecto.Repo.config/0.

custom_preload_fun(fun)

default_options(operation)

Callback implementation for Ecto.Repo.default_options/1.

default_repo_opts()

disconnect_all(interval, opts \\ [])

A convenience function for SQL-based repositories that forces all connections in the pool to disconnect within the given interval.

See Ecto.Adapters.SQL.disconnect_all/3 for more information.

exists?(queryable, opts \\ [])

Callback implementation for Ecto.Repo.exists?/2.

explain(operation, queryable, opts \\ [])

A convenience function for SQL-based repositories that executes an EXPLAIN statement or similar depending on the adapter to obtain statistics for the given query.

See Ecto.Adapters.SQL.explain/4 for more information.

fetch(queryable, id)

@spec fetch(atom(), integer() | binary()) :: {:ok, atom()} | {:error, :not_found}

Execute a query for one result where the primary key matches the given id, and return either an {:ok, result} tuple or a {:error, :not_found}.

Examples

iex> fetch(User, 1)
{:ok, %User{}}

iex> fetch(User, 999)
{:error, :not_found}

fetch_all(queryable, id_or_ids)

Execute a query for multiple results given one or multiple IDs.

Examples

iex> fetch_all(User, [1, 2, 3])
[%User{}, %User{}, %User{}]

iex> fetch_all(User, 999)
[]

fetch_by(queryable, term)

Execute a query for one result (using a keyword list to specify the key/value to query with), and return either an {:ok, result} tuple or a {:error, :not_found}.

Examples

iex> fetch_by(User, name: "Alice")
{:ok, %User{}}

iex> fetch_by(User, name: "Nonexistent")
{:error, :not_found}

find(q, changeset, field \\ :form)

Like single/1, except on failure, adds an error to the changeset.

Examples

iex> changeset = %Ecto.Changeset{}
iex> find(from u in User, where: u.id == 1, changeset)
{:ok, %User{}}

iex> changeset = %Ecto.Changeset{}
iex> find(from u in User, where: u.id == 999, changeset)
{:error, %Ecto.Changeset{}}

get(queryable, id, opts \\ [])

Callback implementation for Ecto.Repo.get/3.

get!(queryable, id, opts \\ [])

Callback implementation for Ecto.Repo.get!/3.

get_by(queryable, clauses, opts \\ [])

Callback implementation for Ecto.Repo.get_by/3.

get_by!(queryable, clauses, opts \\ [])

Callback implementation for Ecto.Repo.get_by!/3.

get_dynamic_repo()

Callback implementation for Ecto.Repo.get_dynamic_repo/0.

in_transaction?()

Callback implementation for Ecto.Repo.in_transaction?/0.

load(schema_or_types, data)

Callback implementation for Ecto.Repo.load/2.

make_subquery(query)

many(query, opts \\ [])

Execute a query for multiple results and return the results.

Examples

iex> many(from u in User)
[%User{}, %User{}]

iex> many(from u in User, return: :query)
#Ecto.Query<...>

many_paginated(queryable, opts \\ [], repo_opts \\ default_repo_opts())

Execute a query for multiple results and return one page of results. This uses the main implementation for pagination, which is cursor-based and powered by the Paginator library.

Examples

iex> many_paginated(User, [limit: 10])
%Paginator.Page{}

maybe_one(q, fallback \\ nil)

Execute a query for one result and return either a result or a fallback value (nil by default).

Examples

iex> maybe_one(from u in User, where: u.id == 1)
%User{}

iex> maybe_one(from u in User, where: u.id == 999, "fallback")
"fallback"

maybe_preload(obj, preloads, opts \\ [])

See Bonfire.Common.Repo.Preload.maybe_preload/3.

maybe_where_ilike(query, field, user_query, system_prefix \\ "", system_suffix \\ "")

Add an ilike clause to a query if the user query is safe.

Examples

iex> maybe_where_ilike(Needle.Pointer, :id, "Alice")
#Ecto.Query<...>

iex> maybe_where_ilike(Needle.Pointer, :id, "Al%ice")
Needle.Pointer 
# ^ unchanged due to unsafe query

one(queryable, opts \\ [])

Callback implementation for Ecto.Repo.one/2.

one!(queryable, opts \\ [])

Callback implementation for Ecto.Repo.one!/2.

paginate(pageable, options \\ [])

Different implementation for pagination using Scrivener (used by eg. rauversion).

Examples

iex> paginate(User, page: 1, page_size: 10)
%Scrivener.Page{}

pagination_opts(opts)

pluck(query, fields, opts \\ [])

Select and return only specific fields (specified as an atom or list of atoms)

Examples

> pluck(:id)
[id1, id2]

> pluck([:id, :inserted_at])
[%{id: id1, inserted_at: _}, %{id: id2, inserted_at: _}]

preload(struct_or_structs_or_nil, preloads, opts \\ [])

Callback implementation for Ecto.Repo.preload/3.

preload_all(obj, opts \\ [])

See Bonfire.Common.Repo.Preload.preload_all/2.

preload_mixins(obj, opts \\ [])

See Bonfire.Common.Repo.Preload.preload_mixins/2.

prepare_query(operation, query, opts)

Callback implementation for Ecto.Repo.prepare_query/3.

prepare_transaction(fun_or_multi, opts)

Callback implementation for Ecto.Repo.prepare_transaction/2.

put_dynamic_repo(dynamic)

Callback implementation for Ecto.Repo.put_dynamic_repo/1.

query(sql, params \\ [], opts \\ [])

A convenience function for SQL-based repositories that executes the given query.

See Ecto.Adapters.SQL.query/4 for more information.

query!(sql, params \\ [], opts \\ [])

A convenience function for SQL-based repositories that executes the given query.

See Ecto.Adapters.SQL.query!/4 for more information.

query_many(sql, params \\ [], opts \\ [])

A convenience function for SQL-based repositories that executes the given multi-result query.

See Ecto.Adapters.SQL.query_many/4 for more information.

query_many!(sql, params \\ [], opts \\ [])

A convenience function for SQL-based repositories that executes the given multi-result query.

See Ecto.Adapters.SQL.query_many!/4 for more information.

reject_preload_ids(exclude_ids)

reload(queryable, opts \\ [])

Callback implementation for Ecto.Repo.reload/2.

reload!(queryable, opts \\ [])

Callback implementation for Ecto.Repo.reload!/2.

rollback(value)

@spec rollback(term()) :: no_return()

Callback implementation for Ecto.Repo.rollback/1.

single(q)

Execute a query for one result and return either an {:ok, result} or {:error, :not_found} tuple.

Examples

iex> single(from u in User, where: u.id == 1)
{:ok, %User{}}

iex> single(from u in User, where: u.id == 999)
{:error, :not_found}

sql(raw_sql, data \\ [], opts \\ [])

Executes raw SQL query.

Examples

> YourModule.sql("SELECT * FROM pointers")

start_link(opts \\ [])

Callback implementation for Ecto.Repo.start_link/1.

stop(timeout \\ 5000)

Callback implementation for Ecto.Repo.stop/1.

stream(queryable, opts \\ [])

Callback implementation for Ecto.Repo.stream/2.

to_sql(operation, queryable)

A convenience function for SQL-based repositories that translates the given query to SQL.

See Ecto.Adapters.SQL.to_sql/3 for more information.

trace(fun)

Can be used to log specific queries (by calling function) in production.

Examples

iex> trace(fn -> Repo.all(User) end)
[%User{}, %User{}]

transact(fun_or_multi, opts \\ [])

Callback implementation for Ecto.Repo.transact/2.

transact_many(queries)

transact_with(fun, opts \\ [])

Run a transaction, similar to Repo.transaction/1, but it expects an ok or error tuple. If an error tuple is returned, the transaction is aborted.

Examples

iex> transact_with(fn -> {:ok, "success"} end)
"success"

iex> transact_with(fn -> {:error, "failure"} end)
** (Ecto.RollbackError) Rolling back the DB transaction, error reason: failure

transaction(fun_or_multi, opts \\ [])

Callback implementation for Ecto.Repo.transaction/2.