View Source Lightning.Collections (Lightning v2.10.4)
Access to collections of unique key-value pairs shared across multiple workflows.
Summary
Functions
Creates a new collection with the given attributes.
Returns the list of collections with optional ordering and preloading.
Updates an existing collection with the given attributes.
Functions
@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.
@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}
@spec delete_all(Lightning.Collections.Collection.t(), String.t() | nil) :: {:ok, non_neg_integer()}
@spec delete_collection(Ecto.UUID.t()) :: {:ok, Lightning.Collections.Collection.t()} | {:error, Ecto.Changeset.t()} | {:error, :not_found}
@spec get(Lightning.Collections.Collection.t(), String.t()) :: Lightning.Collections.Item.t() | nil
@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}
@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()}
@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.