View Source Indexed (Indexed v0.1.0)

Tools for creating an index module.

Link to this section Summary

Types

A function which takes a record and returns a value which will be evaluated for truthiness. If true, the value will be included in the result set.

The value of a record's :id field - usually a UUID or integer.

A lookup index allows quickly finding record ids by their field values.

A value to prefix ETS table names.

A parameter to indicate a sort field and optionally direction.

Specifies a discrete data set of an entity, pre-partitioned into a group. A tuple indicates a field name and value which must match, a string indicates a view fingerprint, and nil means the full data set.

A record map being cached & indexed. :id key is required.

t()
  • :entities - Map of entity name keys to Indexed.Entity.t/0
  • :index_ref - ETS table reference for all indexed data.

Reference to a table. If an atom, then a namespace is in use.

Map held in ETS - tracks all views and their created timestamps.

Functions

Get the name of the first indexed field for an entity. Good order_hint default.

Get the ETS options to be used for any and all tables.

Get a record by id from the index.

Get an index data structure by key.

Get an index data structure.

Get a list of all cached records of a certain type.

For the given data set, get a list (sorted ascending) of unique values for field_name under entity_name. Returns nil if no data is found.

For the given prefilter, get a map where keys are unique values for field_name under entity_name and vals are occurrence counts. Returns nil if no data is found.

Get a particular view struct (view metadata) by its fingerprint.

Get a map of fingerprints to view structs (view metadata).

Cache key for a given entity, field and direction.

Cache key for a lookup map of the given entity's records: %{"Some Field Value" => [123, 456]}

Get an ETS table reference or name for an entity name. Default with no entity_name is indexes table ref.

Build an ETS table name from its namespace and entity_name.

Cache key holding unique values for a given entity and field.

Cache key holding unique values & counts for a given entity and field.

Cache key holding views/0 for a certain entity.

Link to this section Types

@type filter() :: (record() -> any())

A function which takes a record and returns a value which will be evaluated for truthiness. If true, the value will be included in the result set.

@type id() :: any()

The value of a record's :id field - usually a UUID or integer.

@type lookup() :: %{required(any()) => [id()]}

A lookup index allows quickly finding record ids by their field values.

@type namespace() :: atom()

A value to prefix ETS table names.

@type order_hint() ::
  atom()
  | {direction :: :asc | :desc, field_name :: atom()}
  | [{:asc | :desc, atom()}]

A parameter to indicate a sort field and optionally direction.

@type prefilter() :: {atom(), any()} | String.t() | nil

Specifies a discrete data set of an entity, pre-partitioned into a group. A tuple indicates a field name and value which must match, a string indicates a view fingerprint, and nil means the full data set.

@type record() :: map()

A record map being cached & indexed. :id key is required.

@type t() :: %Indexed{
  entities: %{required(atom()) => Indexed.Entity.t()},
  index_ref: table_ref()
}
  • :entities - Map of entity name keys to Indexed.Entity.t/0
  • :index_ref - ETS table reference for all indexed data.
@type table_ref() :: atom() | :ets.tid()

Reference to a table. If an atom, then a namespace is in use.

@type views() :: %{required(String.t()) => DateTime.t()}

Map held in ETS - tracks all views and their created timestamps.

Link to this section Functions

Link to this function

create_view(index, entity_name, fp, opts)

View Source

See Indexed.Actions.CreateView.run/4.

Link to this function

default_order_hint(index, entity_name)

View Source
@spec default_order_hint(t(), atom()) :: atom()

Get the name of the first indexed field for an entity. Good order_hint default.

Link to this function

destroy_view(index, entity_name, fp)

View Source

See Indexed.Actions.DestroyView.run/3.

Link to this function

drop(index, entity_name, id)

View Source

See Indexed.Actions.Drop.run/3.

@spec ets_opts(namespace() | nil) :: keyword()

Get the ETS options to be used for any and all tables.

Link to this function

get(index, entity_name, id, default \\ nil)

View Source
@spec get(t(), atom(), id(), any()) :: any()

Get a record by id from the index.

Link to this function

get_by(index, name, field, value)

View Source
@spec get_by(t(), atom(), atom(), any()) :: [record()]
Link to this function

get_index(index, index_key, default \\ nil)

View Source
@spec get_index(t(), String.t(), any()) :: any()

Get an index data structure by key.

Link to this function

get_index(index, entity_name, prefilter, order_hint)

View Source
@spec get_index(t(), atom(), prefilter(), order_hint() | nil) :: list() | map() | nil

Get an index data structure.

Link to this function

get_lookup(index, entity_name, field_name)

View Source
@spec get_lookup(t(), atom(), atom()) :: lookup() | nil

Get an index data structure.

Link to this function

get_records(index, entity_name, prefilter, order_hint \\ nil)

View Source
@spec get_records(t(), atom(), prefilter(), order_hint() | nil) :: [record()]

Get a list of all cached records of a certain type.

prefilter - 2-element tuple (prefilter/0) indicating which sub-section of the data should be queried. Default is nil - no prefilter.

Link to this function

get_uniques_list(index, entity_name, prefilter, field_name)

View Source
@spec get_uniques_list(t(), atom(), prefilter(), atom()) :: list()

For the given data set, get a list (sorted ascending) of unique values for field_name under entity_name. Returns nil if no data is found.

Link to this function

get_uniques_map(index, entity_name, prefilter, field_name)

View Source
@spec get_uniques_map(t(), atom(), prefilter(), atom()) ::
  Indexed.UniquesBundle.counts_map()

For the given prefilter, get a map where keys are unique values for field_name under entity_name and vals are occurrence counts. Returns nil if no data is found.

Link to this function

get_view(index, entity_name, fingerprint)

View Source
@spec get_view(t(), atom(), Indexed.View.fingerprint()) :: Indexed.View.t() | nil

Get a particular view struct (view metadata) by its fingerprint.

Link to this function

get_views(index, entity_name)

View Source
@spec get_views(t(), atom()) :: %{
  required(Indexed.View.fingerprint()) => Indexed.View.t()
}

Get a map of fingerprints to view structs (view metadata).

Link to this function

index_key(entity_name, prefilter, order_hint)

View Source
@spec index_key(atom(), prefilter(), order_hint()) :: String.t()

Cache key for a given entity, field and direction.

Link to this function

lookup(index, name, field, value)

View Source
@spec lookup(t(), atom(), atom(), any()) :: [record()]
Link to this function

lookup_ids(index, name, field, value)

View Source
@spec lookup_ids(t(), atom(), atom(), any()) :: [id()]
Link to this function

lookup_key(entity_name, field)

View Source
@spec lookup_key(atom(), atom()) :: String.t()

Cache key for a lookup map of the given entity's records: %{"Some Field Value" => [123, 456]}

Link to this function

paginate(index, entity_name, params)

View Source

See Indexed.Actions.Paginate.run/3.

See Indexed.Actions.Warm.run/1.

Link to this function

put(index, entity_name, record)

View Source

See Indexed.Actions.Put.run/3.

Link to this function

ref(index, entity_name \\ nil)

View Source
@spec ref(t(), atom()) :: table_ref()

Get an ETS table reference or name for an entity name. Default with no entity_name is indexes table ref.

Link to this function

table_name(namespace \\ nil, entity_name \\ nil)

View Source
@spec table_name(namespace() | nil, atom()) :: atom()

Build an ETS table name from its namespace and entity_name.

Link to this function

uniques_list_key(entity_name, prefilter, field_name)

View Source
@spec uniques_list_key(atom(), prefilter(), atom()) :: String.t()

Cache key holding unique values for a given entity and field.

Link to this function

uniques_map_key(entity_name, prefilter, field_name)

View Source
@spec uniques_map_key(atom(), prefilter(), atom()) :: String.t()

Cache key holding unique values & counts for a given entity and field.

@spec views_key(atom()) :: String.t()

Cache key holding views/0 for a certain entity.

See Indexed.Actions.Warm.run/1.