View Source Lightning.Collections (Lightning v2.10.4)

Access to collections of unique key-value pairs shared across multiple workflows.

Summary

Functions

Link to this function

create_collection(attrs)

View Source
@spec create_collection(map()) ::
  {:ok, Lightning.Collections.Collection.t()} | {:error, Ecto.Changeset.t()}

Creates a new collection with the given attributes.

Parameters

  • attrs: A map of attributes to create the collection.

Examples

iex> create_collection(%{name: "New Collection", description: "Description here"})
{:ok, %Collection{}}

iex> create_collection(%{name: nil})
{:error, %Ecto.Changeset{}}

Returns

  • {:ok, %Collection{}} on success.
  • {:error, %Ecto.Changeset{}} on failure due to validation errors.
Link to this function

create_collection(project_id, name)

View Source
@spec create_collection(Ecto.UUID.t(), String.t()) ::
  {:ok, Lightning.Collections.Collection.t()} | {:error, Ecto.Changeset.t()}
@spec delete(Lightning.Collections.Collection.t(), String.t()) ::
  :ok | {:error, :not_found}
Link to this function

delete_all(map, key_pattern \\ nil)

View Source
@spec delete_all(Lightning.Collections.Collection.t(), String.t() | nil) ::
  {:ok, non_neg_integer()}
Link to this function

delete_collection(collection_id)

View Source
@spec delete_collection(Ecto.UUID.t()) ::
  {:ok, Lightning.Collections.Collection.t()}
  | {:error, Ecto.Changeset.t()}
  | {:error, :not_found}
Link to this function

get_all(map, params, key_pattern \\ nil)

View Source
@spec get_all(Lightning.Collections.Collection.t(), Enum.t(), String.t() | nil) ::
  Enum.t()
@spec get_collection(String.t()) ::
  {:ok, Lightning.Collections.Collection.t()} | {:error, :not_found}
Link to this function

list_collections(opts \\ [])

View Source
@spec list_collections(keyword()) :: [Lightning.Collections.Collection.t()]

Returns the list of collections with optional ordering and preloading.

Parameters

  • opts: A keyword list of options.
    • :order_by (optional): The field by which to order the results. Default is [asc: :name].
    • :preload (optional): A list of associations to preload. Default is [:project].

Examples

iex> list_collections()
[%Collection{}, ...]

iex> list_collections(order_by: [asc: :inserted_at], preload: [:project, :user])
[%Collection{}, ...]

Returns

  • A list of %Collection{} structs, preloaded and ordered as specified.
@spec put(Lightning.Collections.Collection.t(), String.t(), String.t()) ::
  :ok | {:error, Ecto.Changeset.t()}
@spec put_all(Lightning.Collections.Collection.t(), [{String.t(), String.t()}]) ::
  {:ok, non_neg_integer()}
Link to this function

update_collection(collection, attrs)

View Source
@spec update_collection(Lightning.Collections.Collection.t(), map()) ::
  {:ok, Lightning.Collections.Collection.t()} | {:error, Ecto.Changeset.t()}

Updates an existing collection with the given attributes.

Parameters

  • collection: The existing %Collection{} struct to update.
  • attrs: A map of attributes to update the collection.

Examples

iex> update_collection(collection, %{name: "Updated Name"})
{:ok, %Collection{}}

iex> update_collection(collection, %{name: nil})
{:error, %Ecto.Changeset{}}

Returns

  • {:ok, %Collection{}} on success.
  • {:error, %Ecto.Changeset{}} on failure due to validation errors.