Glific v0.3.1 Glific.Repo View Source

A repository that maps to an underlying data store, controlled by the Postgres adapter.

We add a few functions to make our life easier with a few helper functions that ecto does not provide.

Link to this section Summary

Functions

Callback implementation for Ecto.Repo.all/2.

Callback implementation for Ecto.Repo.checkout/2.

Callback implementation for Ecto.Repo.config/0.

We use this function also in most list_OBJECT api's, where we process the the filter. Centralizing this code at the top level, to make things cleaner

Callback implementation for Ecto.Repo.delete/2.

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

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids.

Glific version of get, which returns a tuple with an :ok | :error as the first element

Glific version of get_by, which returns a tuple with an :ok | :error as the first element

Add all the common filters here, rather than in each file

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.insert/2.

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

Get map of field (typically label) to ids for easier lookup for various system objects - language, tag

Extracts the limit offset field, and adds to query

We use this function in most list_OBJECT api's, where we process the opts and the filter. Centralizing this code at the top level, to make things cleaner

Callback implementation for Ecto.Repo.load/2.

Callback implementation for Ecto.Repo.one/2.

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

A funtion which handles the order clause for a data type that has a 'name/body/label' in its schema (which is true for a fair number of Glific's data types)

An empty function for objects that ignore the opts

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

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

Callback implementation for Ecto.Repo.rollback/1.

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.

Callback implementation for Ecto.Repo.update/2.

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

Link to this section Functions

Link to this function

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

View Source

Callback implementation for Ecto.Repo.aggregate/3.

Link to this function

aggregate(queryable, aggregate, field, opts)

View Source

Callback implementation for Ecto.Repo.aggregate/4.

Link to this function

all(queryable, opts \\ [])

View Source

Callback implementation for Ecto.Repo.all/2.

Link to this function

checkout(fun, opts \\ [])

View Source

Callback implementation for Ecto.Repo.checkout/2.

Callback implementation for Ecto.Repo.config/0.

Link to this function

count_filter(args \\ %{}, object, filter_with_fn)

View Source

Specs

count_filter(
  map(),
  atom(),
  (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t())
) :: integer()

We use this function also in most list_OBJECT api's, where we process the the filter. Centralizing this code at the top level, to make things cleaner

Link to this function

default_options(operation)

View Source

Callback implementation for Ecto.Repo.default_options/1.

Link to this function

delete(struct, opts \\ [])

View Source

Callback implementation for Ecto.Repo.delete/2.

Link to this function

delete!(struct, opts \\ [])

View Source

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

Link to this function

delete_all(queryable, opts \\ [])

View Source

Callback implementation for Ecto.Repo.delete_all/2.

Link to this function

delete_relationships_by_ids(object, fields)

View Source

Specs

delete_relationships_by_ids(
  atom(),
  {{atom(), integer()}, {atom(), [integer()]}}
) :: {integer(), nil | [term()]}

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids.

Link to this function

exists?(queryable, opts \\ [])

View Source

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

Link to this function

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

View Source

Specs

fetch(Ecto.Queryable.t(), term(), Keyword.t()) ::
  {:ok, Ecto.Schema.t()} | {:error, [String.t()]}

Glific version of get, which returns a tuple with an :ok | :error as the first element

Link to this function

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

View Source

Specs

fetch_by(Ecto.Queryable.t(), Keyword.t() | map(), Keyword.t()) ::
  {atom(), Ecto.Schema.t() | String.t()}

Glific version of get_by, which returns a tuple with an :ok | :error as the first element

Link to this function

filter_with(query, filter)

View Source

Specs

filter_with(Ecto.Queryable.t(), %{optional(atom()) => any()}) ::
  Ecto.Queryable.t()

Add all the common filters here, rather than in each file

Link to this function

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

View Source

Callback implementation for Ecto.Repo.get/3.

Link to this function

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

View Source

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

Link to this function

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

View Source

Callback implementation for Ecto.Repo.get_by/3.

Link to this function

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

View Source

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

Callback implementation for Ecto.Repo.get_dynamic_repo/0.

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

Link to this function

insert(struct, opts \\ [])

View Source

Callback implementation for Ecto.Repo.insert/2.

Link to this function

insert!(struct, opts \\ [])

View Source

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

Link to this function

insert_all(schema_or_source, entries, opts \\ [])

View Source

Callback implementation for Ecto.Repo.insert_all/3.

Link to this function

insert_or_update(changeset, opts \\ [])

View Source

Callback implementation for Ecto.Repo.insert_or_update/2.

Link to this function

insert_or_update!(changeset, opts \\ [])

View Source

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

Link to this function

label_id_map(queryable, values, organization_id, field \\ :label)

View Source

Specs

label_id_map(Ecto.Queryable.t(), [String.t()], non_neg_integer(), atom()) :: %{
  required(String.t()) => integer()
}

Get map of field (typically label) to ids for easier lookup for various system objects - language, tag

Link to this function

limit_offset(query, opts)

View Source

Specs

limit_offset(Ecto.Queryable.t(), map()) :: Ecto.Queryable.t()

Extracts the limit offset field, and adds to query

Link to this function

list_filter(args \\ %{}, object, opts_with_fn, filter_with_fn)

View Source

Specs

list_filter(
  map(),
  atom(),
  (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()),
  (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t())
) :: [any()]

We use this function in most list_OBJECT api's, where we process the opts and the filter. Centralizing this code at the top level, to make things cleaner

Link to this function

load(schema_or_types, data)

View Source

Callback implementation for Ecto.Repo.load/2.

Link to this function

one(queryable, opts \\ [])

View Source

Callback implementation for Ecto.Repo.one/2.

Link to this function

one!(queryable, opts \\ [])

View Source

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

Link to this function

opts_with_field(query, opts, field)

View Source

Specs

opts_with_field(Ecto.Queryable.t(), map(), :name | :body | :label) ::
  Ecto.Queryable.t()

A funtion which handles the order clause for a data type that has a 'name/body/label' in its schema (which is true for a fair number of Glific's data types)

Link to this function

opts_with_nil(opts, query)

View Source

Specs

opts_with_nil(any(), any()) :: any()

An empty function for objects that ignore the opts

Link to this function

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

View Source

Callback implementation for Ecto.Repo.preload/3.

Link to this function

prepare_query(operation, query, opts)

View Source

Callback implementation for Ecto.Repo.prepare_query/3.

Link to this function

put_dynamic_repo(dynamic)

View Source

Callback implementation for Ecto.Repo.put_dynamic_repo/1.

Link to this function

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

View Source

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

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

Link to this function

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

View Source

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

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

Specs

rollback(term()) :: no_return()

Callback implementation for Ecto.Repo.rollback/1.

Callback implementation for Ecto.Repo.start_link/1.

Callback implementation for Ecto.Repo.stop/1.

Link to this function

stream(queryable, opts \\ [])

View Source

Callback implementation for Ecto.Repo.stream/2.

Link to this function

to_sql(operation, queryable)

View Source

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

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

Link to this function

transaction(fun_or_multi, opts \\ [])

View Source

Callback implementation for Ecto.Repo.transaction/2.

Link to this function

update(struct, opts \\ [])

View Source

Callback implementation for Ecto.Repo.update/2.

Link to this function

update!(struct, opts \\ [])

View Source

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

Link to this function

update_all(queryable, updates, opts \\ [])

View Source

Callback implementation for Ecto.Repo.update_all/3.