View Source Needle.Tables (Bonfire v0.9.10-classic-beta.169)

A Global cache of Tables to be queried by their (Pointer) IDs, table names or Ecto Schema module names.

Use of the Table Service requires:

  1. You have run the migrations shipped with this library.
  2. You have started Needle.Tables before querying.
  3. All OTP applications with pointable Ecto Schemata to be added to the schema path.
  4. OTP 21.2 or greater, though we recommend using the most recent release available.

While this module is a GenServer, it is only responsible for setup of the cache and then exits with :ignore having done so. It is not recommended to restart the service as this will lead to a stop the world garbage collection of all processes and the copying of the entire cache to each process that has queried it since its last local garbage collection.

Summary

Types

A query is either a table's (database) name or (Pointer) ID as a binary or the name of its Ecto Schema Module as an atom.

Functions

Returns a specification to start this module under a supervisor.

Look up a table id by id, name or schema.

Look up a table id by id, name or schema, raise NotFound if not found.

Look up many ids at once, raise NotFound if any of them are not found

Look up a schema module by id, name or schema

Look up a schema module by id, name or schema, raise NotFound if not found

Populates the global cache with table data via introspection.

Get a Table identified by name, id or module.

Look up a Table by name or id, raise NotFound if not found.

Types

@type query() :: binary() | atom()

A query is either a table's (database) name or (Pointer) ID as a binary or the name of its Ecto Schema Module as an atom.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec id(query()) :: {:ok, integer()} | {:error, Needle.NotFound.t()}

Look up a table id by id, name or schema.

@spec id!(query()) :: integer()

Look up a table id by id, name or schema, raise NotFound if not found.

@spec ids!([binary() | atom()]) :: [binary()]

Look up many ids at once, raise NotFound if any of them are not found

@spec schema(query()) :: {:ok, atom()} | {:error, Needle.NotFound.t()}

Look up a schema module by id, name or schema

@spec schema!(query()) :: atom()

Look up a schema module by id, name or schema, raise NotFound if not found

@spec start_link(ignored :: term()) :: GenServer.on_start()

Populates the global cache with table data via introspection.

@spec table(query :: query()) ::
  {:ok, Needle.Table.t()} | {:error, Needle.NotFound.t()}

Get a Table identified by name, id or module.

@spec table!(query()) :: Needle.Table.t()

Look up a Table by name or id, raise NotFound if not found.