View Source Indexed (Indexed v0.0.1)

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 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 the indexes.

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 an entity by id from the index.

Get an index data structure by key.

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 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 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: %{optional(atom()) => Indexed.Entity.t()},
  index_ref: :ets.tid()
}
  • :entities - Map of entity name keys to Indexed.Entity.t/0
  • :index_ref - ETS table reference for the indexes.
@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() :: 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 an entity by id from the index.

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_records(index, entity_name, prefilter, order_hint \\ nil)

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

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() | nil

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() | nil

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

paginate(index, entity_name, params)

View Source

See Indexed.Actions.Paginate.run/3.

Link to this function

put(index, entity_name, record)

View Source

See Indexed.Actions.Put.run/3.

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.