View Source Glific.Repo (Glific v5.1.6)
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
Implement permission support via groups. This is the basic wrapper, it uses a context specific permission wrapper to add the actual clauses
Callback implementation for Ecto.Repo.aggregate/3
.
Callback implementation for Ecto.Repo.aggregate/4
.
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
.
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
.
Callback implementation for Ecto.Repo.delete_all/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.
A convenience function for SQL-based repositories that forces all connections in the pool to disconnect within the given interval.
Callback implementation for Ecto.Repo.exists?/2
.
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.
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_by/3
.
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
.
Callback implementation for Ecto.Repo.insert/2
.
Callback implementation for Ecto.Repo.insert!/2
.
Callback implementation for Ecto.Repo.insert_all/3
.
Callback implementation for Ecto.Repo.insert_or_update/2
.
Callback implementation for Ecto.Repo.insert_or_update!/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
This function builds the query, and is used in places where we want to layer permission on top of the query
Callback implementation for Ecto.Repo.load/2
.
Callback implementation for Ecto.Repo.one/2
.
Callback implementation for Ecto.Repo.one!/2
.
A function 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
Callback implementation for Ecto.Repo.preload/3
.
Callback implementation for Ecto.Repo.put_dynamic_repo/1
.
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.reload!/2
.
Callback implementation for Ecto.Repo.rollback/1
.
Can we skip checking permissions for this user. This eliminates a DB call in many a case
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.transaction/2
.
Callback implementation for Ecto.Repo.update/2
.
Callback implementation for Ecto.Repo.update!/2
.
Callback implementation for Ecto.Repo.update_all/3
.
Link to this section Functions
@spec add_permission( Ecto.Query.t(), (Ecto.Query.t(), Glific.Users.User.t() -> Ecto.Query.t()), boolean() ) :: Ecto.Query.t()
Implement permission support via groups. This is the basic wrapper, it uses a context specific permission wrapper to add the actual clauses
Callback implementation for Ecto.Repo.aggregate/3
.
Callback implementation for Ecto.Repo.aggregate/4
.
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
.
count_filter(args \\ %{}, object, filter_with_fn, repo_opts \\ [])
View Source@spec count_filter( map(), atom(), (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()), Keyword.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
Callback implementation for Ecto.Repo.delete/2
.
Callback implementation for Ecto.Repo.delete!/2
.
Callback implementation for Ecto.Repo.delete_all/2
.
@spec 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.
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.
Callback implementation for Ecto.Repo.exists?/2
.
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.
@spec 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
@spec fetch_by(Ecto.Queryable.t(), Keyword.t() | map(), Keyword.t()) :: {:ok, Ecto.Schema.t()} | {:error, [String.t()]}
Glific version of get_by, which returns a tuple with an :ok | :error as the first element
@spec filter_with(Ecto.Queryable.t(), %{optional(atom()) => any()}) :: Ecto.Queryable.t()
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_by/3
.
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
.
Callback implementation for Ecto.Repo.insert/2
.
Callback implementation for Ecto.Repo.insert!/2
.
Callback implementation for Ecto.Repo.insert_all/3
.
Callback implementation for Ecto.Repo.insert_or_update/2
.
Callback implementation for Ecto.Repo.insert_or_update!/2
.
@spec 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
@spec limit_offset(Ecto.Queryable.t(), map()) :: Ecto.Queryable.t()
Extracts the limit offset field, and adds to query
list_filter(args \\ %{}, object, opts_with_fn, filter_with_fn, repo_opts \\ [])
View Source@spec list_filter( map(), atom(), (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()), (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()), Keyword.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
list_filter_query(args \\ %{}, object, opts_with_fn, filter_with_fn)
View Source@spec list_filter_query( map(), atom(), (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()) | nil, (Ecto.Queryable.t(), %{optional(atom()) => any()} -> Ecto.Queryable.t()) ) :: Ecto.Queryable.t()
This function builds the query, and is used in places where we want to layer permission on top of the query
Callback implementation for Ecto.Repo.load/2
.
Callback implementation for Ecto.Repo.one/2
.
Callback implementation for Ecto.Repo.one!/2
.
@spec opts_with_field( Ecto.Queryable.t(), map(), :name | :body | :label | :inserted_at | :id ) :: Ecto.Queryable.t()
A function 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)
@spec opts_with_nil(Ecto.Queryable.t(), any()) :: Ecto.Queryable.t()
An empty function for objects that ignore the opts
Callback implementation for Ecto.Repo.preload/3
.
Callback implementation for Ecto.Repo.put_dynamic_repo/1
.
A convenience function for SQL-based repositories that executes the given query.
See Ecto.Adapters.SQL.query/4
for more information.
A convenience function for SQL-based repositories that executes the given query.
See Ecto.Adapters.SQL.query!/4
for more information.
A convenience function for SQL-based repositories that executes the given multi-result query.
See Ecto.Adapters.SQL.query_many/4
for more information.
A convenience function for SQL-based repositories that executes the given multi-result query.
See Ecto.Adapters.SQL.query_many!/4
for more information.
Callback implementation for Ecto.Repo.reload/2
.
Callback implementation for Ecto.Repo.reload!/2
.
Callback implementation for Ecto.Repo.rollback/1
.
@spec skip_permission?(Glific.Users.User.t() | nil) :: boolean()
Can we skip checking permissions for this user. This eliminates a DB call in many a case
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.
See Ecto.Adapters.SQL.to_sql/3
for more information.
Callback implementation for Ecto.Repo.transaction/2
.
Callback implementation for Ecto.Repo.update/2
.
Callback implementation for Ecto.Repo.update!/2
.
Callback implementation for Ecto.Repo.update_all/3
.