Insights.Adapter behaviour

This module specifies the adapter API that an adapter is required to implement.

Source

Types

t :: module

source :: {table :: binary, model :: atom}

Callbacks

all/3

Specs:

  • all(adapter, query, options) :: [[term]] | no_return

Fetches all results from the data store based on the given query. It receives a preprocess function responsible that should be invoked for each selected field in the query result in order to convert them to the expected Insights type.

Source
count/3

Specs:

  • count(adapter, query, options) :: [[term]] | no_return

Count all results from the data store based on the given query. It receives a preprocess function responsible that should be invoked for each selected field in the query result in order to convert them to the expected Insights type.

Source
delete/3

Specs:

  • delete(adapter, query, options) :: {:ok, Keyword.t} | {:error, :stale} | no_return

Deletes a sigle model with the given filters. While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) to be given as filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

Source
insert/3

Specs:

Inserts a single new model in the data store.

Source
start_link/2

Specs:

  • start_link(adapter, options) :: {:ok, pid} | :ok | {:error, {:already_started, pid}} | {:error, term}

Starts any connection pooling or supervision and return {:ok, pid} or just :ok if nothing needs to be done. Returns {:error, {:already_started, pid}} if the adapter already started or {:error, term} in case anything else goes wrong.

Adapter start

Because some Insights tasks like migration may run without starting the parent application, it is recommended that start_link in adapters make sure the adapter application is started by calling Application.ensure_all_started/1.

Source
update/4

Specs:

  • update(adapter, query, source, options) :: {:ok, Keyword.t} | {:error, :stale} | no_return

Updates a single model with the given filters. While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) to be given as filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

Source