EctoCrux v1.1.5 EctoCrux.Schema.Baguettes
Sample module using EctoCrux
defmodule MyApp.Schema.Baguettes do
use EctoCrux, module: MyApp.Schema.Baguette
end
Link to this section Summary
Functions
[Repo] Fetches all entries from the data store.
[Repo] Fetches all entries from the data store matching using opts
Count number of elements
[Repo] Create (insert) a new baguette from attrs
[Repo] Create (insert) a baguette from attrs if it doesn't exist
[Repo] Create (insert) a baguette from attrs if it doesn't exist
[Repo] Deletes a struct using its primary key.
Test if an object with
[Repo] Fetches all results from the clauses.
Similar to find_by/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
Little helper to pick first record
Little helper to pick first records
[Repo] Fetches a single struct from the data store where the primary key matches the given id.
[Repo] Similar to get/2 but raises Ecto.NoResultsError if no record was found.
[Repo] Fetches a single result from the clauses.
Similar to get/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
Similar to get_by/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
Little helper to pick last record. the last baguette is always the best !
Little helper to pick last records.
[Repo] Preloads all associations on the given struct or structs.
Like find_by/1
by returns a stream to handle large requests
[Repo] Updates a changeset using its primary key.
Link to this section Functions
all()
all() :: [Ecto.Schema.t()]
all() :: [Ecto.Schema.t()]
[Repo] Fetches all entries from the data store.
# Fetch all Baguettes
Baguettes.all()
all(opts)
all(opts :: Keyword.t()) :: [Ecto.Schema.t()]
all(opts :: Keyword.t()) :: [Ecto.Schema.t()]
[Repo] Fetches all entries from the data store matching using opts
# Fetch all french Baguettes
Baguettes.all(prefix: "francaise")
count()
count() :: integer()
count() :: integer()
Count number of elements
baguettes_count = Baguettes.count()
count(opts)
create(attrs \\ %{})
create(attrs :: map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
create(attrs :: map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
[Repo] Create (insert) a new baguette from attrs
# Create a new baguette with `:kind` value set to `:tradition`
{:ok, baguette} = Baguettes.create(%{kind: :tradition})
create_if_not_exist(attrs)
create_if_not_exist(attrs :: map()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
create_if_not_exist(presence_attrs :: map()) :: {:ok, Ecto.Schema.t()}
create_if_not_exist(attrs :: map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
create_if_not_exist(presence_attrs :: map()) :: {:ok, Ecto.Schema.t()}
[Repo] Create (insert) a baguette from attrs if it doesn't exist
# Create a new baguette with `:kind` value set to `:tradition`
baguette = Baguettes.create(%{kind: :tradition})
# Create another one with the same kind
{:ok, another_ baguette} = Baguettes.create_if_not_exist(%{kind: :tradition})
# `baguette` and `another_baguette` are the same `Baguette`
create_if_not_exist(presence_attrs, creation_attrs)
create_if_not_exist(presence_attrs :: map(), creation_attrs :: map()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
create_if_not_exist(presence_attrs :: map(), creation_attrs :: map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
[Repo] Create (insert) a baguette from attrs if it doesn't exist
Like create_if_not_exist/1
but you can specify attrs for the presence test, and creation attrs.
delete(blob, opts \\ [])
delete(blob :: Ecto.Schema.t(), opts :: Keyword.t()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
delete(blob :: Ecto.Schema.t(), opts :: Keyword.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
[Repo] Deletes a struct using its primary key.
{:ok, deleted_baguette} = Baguettes.delete(baguette)
exist?(presence_attrs)
Test if an object with
find_by(filters)
find_by(filters :: Keyword.t() | map()) :: [Ecto.Schema.t()]
find_by(filters :: Keyword.t() | map()) :: [Ecto.Schema.t()]
[Repo] Fetches all results from the clauses.
best_baguettes = Baguettes.find_by(kind: :best)
find_by(filters, opts)
find_by(filters :: Keyword.t() | map(), opts :: Keyword.t()) :: [
Ecto.Schema.t()
]
find_by(filters :: Keyword.t() | map(), opts :: Keyword.t()) :: [ Ecto.Schema.t() ]
find_undeleted_by(filters)
find_undeleted_by(filters :: Keyword.t() | map()) :: [Ecto.Schema.t()]
find_undeleted_by(filters :: Keyword.t() | map()) :: [Ecto.Schema.t()]
Similar to find_by/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
best_baguettes = Baguettes.find_by(kind: :best)
first()
first() :: Ecto.Schema.t()
first() :: Ecto.Schema.t()
Little helper to pick first record
first_baguette = Baguettes.first()
first(count)
first(count :: term()) :: [Ecto.Schema.t()]
first(count :: term()) :: [Ecto.Schema.t()]
Little helper to pick first records
first_baguettes = Baguettes.first(42)
get(id, opts \\ [])
get(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
get(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
[Repo] Fetches a single struct from the data store where the primary key matches the given id.
# Get the baguette with id primary key `01DACBCR6REMDH6446VCQEZ5EC`
Baguettes.get("01DACBCR6REMDH6446VCQEZ5EC")
# Get the baguette with id primary key `01DACBCR6REMDH6446VCQEZ5EC` and preload it's bakery and flavor
Baguettes.get("01DACBCR6REMDH6446VCQEZ5EC", preloads: [:bakery, :flavor])
note: preloads option is an crux additional feature
get!(id, opts \\ [])
get!(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
get!(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
[Repo] Similar to get/2 but raises Ecto.NoResultsError if no record was found.
# Get the baguette with id primary key `01DACBCR6REMDH6446VCQEZ5EC`
Baguettes.get!("01DACBCR6REMDH6446VCQEZ5EC")
get_by(clauses, opts \\ [])
get_by(clauses :: Keyword.t() | map(), opts :: Keyword.t()) ::
Ecto.Schema.t() | nil
get_by(clauses :: Keyword.t() | map(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
[Repo] Fetches a single result from the clauses.
best_baguette = Baguettes.get_by(kind: :best)
get_undeleted(id, opts \\ [])
get_undeleted(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
get_undeleted(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil
Similar to get/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
get_undeleted_by(clauses)
get_undeleted_by(clauses :: Keyword.t() | map()) :: Ecto.Schema.t() | nil
get_undeleted_by(clauses :: Keyword.t() | map()) :: Ecto.Schema.t() | nil
Similar to get_by/1 but ignore record if column :deleted_at is not nil This is very useful if you use soft_delete features
best_baguette = Baguettes.get_undeleted_by(kind: :best)
last()
last() :: Ecto.Schema.t()
last() :: Ecto.Schema.t()
Little helper to pick last record. the last baguette is always the best !
last_baguette = Baguettes.last()
last(count)
last(count :: term()) :: [Ecto.Schema.t()]
last(count :: term()) :: [Ecto.Schema.t()]
Little helper to pick last records.
last_baguettes = Baguettes.last(42)
preload(blob, preloads, opts \\ [])
preload(structs_or_struct_or_nil, preloads :: term(), opts :: Keyword.t()) ::
structs_or_struct_or_nil
when structs_or_struct_or_nil: [Ecto.Schema.t()] | Ecto.Schema.t() | nil
preload(structs_or_struct_or_nil, preloads :: term(), opts :: Keyword.t()) :: structs_or_struct_or_nil when structs_or_struct_or_nil: [Ecto.Schema.t()] | Ecto.Schema.t() | nil
[Repo] Preloads all associations on the given struct or structs.
my_baguette = Baguettes.preload(baguette, [:floor, :boulanger])
schema_module()
stream(filters \\ [])
Like find_by/1
by returns a stream to handle large requests
Repo.transaction(fn ->
Baguettes.stream(kind: :best)
|> Stream.chunk_every(@chunk_size)
|> Stream.each(fn baguettes_chunk ->
# eat them
end)
|> Stream.run()
end)
update(blob, attrs, opts \\ [])
update(blob :: Ecto.Schema.t(), attrs :: map(), opts :: Keyword.t()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
update(blob :: Ecto.Schema.t(), attrs :: map(), opts :: Keyword.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
[Repo] Updates a changeset using its primary key.
{:ok, updated_baguette} = Baguettes.update(baguette, %{kind: :best})