View Source Resourceful.Collection (Resourceful v0.1.4)

Provides a common interface for querying and retrieving collections.

Deligated modules designed to interact directly with the underlying data or data sources must return alls of resources. For instance, when using Ecto, this module should return alls of structs or maps and not queries that have not been executed yet.

data-sources

Data Sources

A data_source can be another from an Ecto schema, to a module that intteracts with a remote API, to a list as long as there is an underlying module to support the common interfaces. (For now, that's just Ecto.)

Link to this section Summary

Link to this section Types

@type name() :: atom() | String.t()
@type page_info() :: %{
  number: integer(),
  resources: integer(),
  size: integer(),
  total: integer()
}
@type queryable() :: name() | {name(), name()} | Resourceful.Type.queryable()
@type with_page_info() :: {[any()], page_info()}
@type with_page_info(type) :: {[type], page_info()}

Link to this section Functions

Link to this function

all(data_source, opts \\ [])

View Source
@spec all(
  any(),
  keyword()
) :: [any()]

Returns a list of resources that may be filtered and sorted depending on on options. Resources will always be paginated.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options:

Additionally, see settings for the delegated module as it may take additional options.

Link to this function

all_with_page_info(data_source, opts \\ [])

View Source
@spec all_with_page_info(
  any(),
  keyword()
) :: with_page_info()
Link to this function

any?(data_source, opts \\ [])

View Source
@spec any?(
  any(),
  keyword()
) :: boolean()

Checks if data_source contains any resources.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).

@spec default_page_size() :: integer()
Link to this function

filter(data_source, filters, opts \\ [])

View Source
@spec filter(any(), keyword(), keyword()) :: any()
Link to this function

page_info(data_source, opts)

View Source
@spec page_info(
  any(),
  keyword()
) :: page_info()

Returns the total number of resources and pages based on page_size in a data_source.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).

Link to this function

page_info(data_source, page_size, opts \\ [])

View Source
@spec page_info(any(), integer(), keyword()) :: page_info()
Link to this function

page_number_or_default(opts)

View Source
@spec page_number_or_default(keyword()) :: integer()
Link to this function

page_size_or_default(opts)

View Source
@spec page_size_or_default(keyword()) :: integer()
Link to this function

paginate(data_source, opts \\ [])

View Source
@spec paginate(
  any(),
  keyword()
) :: [any()]
Link to this function

paginate(data_source, number, size, opts \\ [])

View Source
@spec paginate(any(), integer(), integer(), keyword()) :: [any()]
Link to this function

paginate_with_info(data_source, opts \\ [])

View Source
@spec paginate_with_info(
  any(),
  keyword()
) :: with_page_info()
Link to this function

query(data_source, opts)

View Source
@spec query(
  any(),
  keyword()
) :: any()
Link to this function

sort(data_source, sorters, opts \\ [])

View Source
@spec sort(any(), keyword(), keyword()) :: any()
Link to this function

total(data_source, opts \\ [])

View Source
@spec total(
  any(),
  keyword()
) :: integer()

Returns the total number of resources in a data_source.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).