View Source Ecto.Adapters.DynamoDB.Query (ecto_adapters_dynamodb v3.5.0)

Some query wrapper functions for helping us query dynamo db. Selects indexes to use, etc. Not to be confused with Ecto.Query.

Summary

Functions

Given a map with a search criteria, finds the best index to search against it. Returns a tuple indicating whether it's a primary key index, or a secondary index. To query against a secondary index in Dynamo, we NEED to have it's index name, so secondary indexes are returned as a tuple with the field name, whilst the primary key uses the atom :primary to distinguish it.

Same as get_best_index, but refers to a scan option on failure

Given a search criteria of 1 or more fields, we try find out if the primary key is a good match and can be used to forfill this search. Returns the tuple {:primary, [hash] | [hash, range]} or :not_found

Given a keyword list containing search field, value and operator to search for (which may also be nested under logical operators, e.g., [{"id", {"franko", :==}}], or [{:and, [{"circle_id", {"123", :==}}, {"person_id", {"abc", :>}}]}), will return the dynamo db index description that will help us match this search. return :not_found if no index is found.

Formats the recursive option according to whether the query is a DynamoDB scan or query. (The adapter defaults to recursive fetch in case of the latter but not the former)

Returns an atom, :scan or :query, specifying whether the current search will be a DynamoDB scan or a query.

Types

dynamo_response()

@type dynamo_response() :: %{required(String.t()) => term()}

expression_data_acc()

@type expression_data_acc() :: {[String.t()], map(), map()}

table_name()

@type table_name() :: String.t()

Functions

construct_search(arg, search, opts)

@spec construct_search(
  {:primary | :primary_partial | nil | String.t(), [String.t()]},
  search(),
  keyword()
) :: keyword()
@spec construct_search(
  {:secondary_partial, String.t(), [String.t()]},
  search(),
  keyword()
) :: keyword()

get_best_index(repo, tablename, search, opts)

@spec get_best_index(Ecto.Repo.t(), table_name(), search(), query_opts()) ::
  :not_found
  | {:primary, [String.t()]}
  | {:primary_partial, [String.t()]}
  | {String.t(), [String.t()]}
  | {:secondary_partial, String.t(), [String.t()]}
  | no_return()

Given a map with a search criteria, finds the best index to search against it. Returns a tuple indicating whether it's a primary key index, or a secondary index. To query against a secondary index in Dynamo, we NEED to have it's index name, so secondary indexes are returned as a tuple with the field name, whilst the primary key uses the atom :primary to distinguish it.

| {"index_name", [indexed_fields_list]}

Exception if the index doesn't exist.

get_best_index!(repo, tablename, search, opts \\ [])

Same as get_best_index, but refers to a scan option on failure

get_item(repo, table, search, opts)

@spec get_item(Ecto.Repo.t(), table_name(), search(), keyword()) ::
  dynamo_response() | no_return()

get_matching_primary_index(repo, tablename, search)

Given a search criteria of 1 or more fields, we try find out if the primary key is a good match and can be used to forfill this search. Returns the tuple {:primary, [hash] | [hash, range]} or :not_found

get_matching_secondary_index(repo, tablename, search, opts)

Given a keyword list containing search field, value and operator to search for (which may also be nested under logical operators, e.g., [{"id", {"franko", :==}}], or [{:and, [{"circle_id", {"123", :==}}, {"person_id", {"abc", :>}}]}), will return the dynamo db index description that will help us match this search. return :not_found if no index is found.

Returns a tuple of {"index_name", [ hash_key or hash,range_key]]} or :not_found TODO: Does not help with range queries. -> The match_index_hash_part function is beginning to address this.

parse_recursive_option(scan_or_query, opts)

Formats the recursive option according to whether the query is a DynamoDB scan or query. (The adapter defaults to recursive fetch in case of the latter but not the former)

scan_or_query?(repo, table, search)

Returns an atom, :scan or :query, specifying whether the current search will be a DynamoDB scan or a query.