EctoCrux v1.1.0 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 the given query.

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.

[Repo] Fetches all results from the clauses.

[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.

[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

[Repo] Fetches all entries from the data store.

##Example

# Fetch all Baguettes
Baguettes.all()
Link to this function

all(opts)
all(opts :: Keyword.t()) :: [Ecto.Schema.t()]

[Repo] Fetches all entries from the data store matching the given query.

##Example

# Fetch all Baguettes
query |> Baguettes.all()
Link to this function

count()
count() :: integer()

Count number of elements

##Example

baguettes_count = Baguettes.count()
Link to this function

create(attrs \\ %{})
create(attrs :: map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

[Repo] Create (insert) a new baguette from attrs

##Example

# Create a new baguette with `:kind` value set to `:tradition`
{:ok, baguette} = Baguettes.create(%{kind: :tradition})
Link to this function

create_if_not_exist(attrs)
create_if_not_exist(attrs :: map()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

[Repo] Create (insert) a baguette from attrs if it doesn't exist

##Example

# 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`
Link to this function

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()}

[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.

Link to this function

delete(blob)
delete(blob :: Ecto.Schema.t()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

[Repo] Deletes a struct using its primary key.

##Example

{:ok, deleted_baguette} = Baguettes.delete(baguette)
Link to this function

find_by(filters)
find_by(filters :: Keyword.t() | map()) :: [Ecto.Schema.t()]

[Repo] Fetches all results from the clauses.

##Example

best_baguettes = Baguettes.find_by(kind: :best)
Link to this function

get(id, opts \\ [])
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.

Example

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

Link to this function

get!(id, opts \\ [])
get!(id :: term(), opts :: Keyword.t()) :: Ecto.Schema.t() | nil

[Repo] Similar to get/2 but raises Ecto.NoResultsError if no record was found.

##Example

# Get the baguette with id primary key `01DACBCR6REMDH6446VCQEZ5EC`
Baguettes.get!("01DACBCR6REMDH6446VCQEZ5EC")
Link to this function

get_by(clauses, opts \\ [])
get_by(clauses :: Keyword.t() | map(), opts :: Keyword.t()) ::
  Ecto.Schema.t() | nil

[Repo] Fetches a single result from the clauses.

##Example

best_baguette = Baguettes.get_by(kind: :best)
Link to this function

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

[Repo] Preloads all associations on the given struct or structs.

##Example

my_baguette = Baguettes.preload(baguette, [:floor, :boulanger])
Link to this function

schema_module()

Link to this function

stream(filters \\ [])
stream(filters :: Keyword.t() | map()) :: Enum.t()

Like find_by/1 by returns a stream to handle large requests

##Example

Repo.transaction(fn ->
  Baguettes.stream(kind: :best)
  |> Stream.chunk_every(@chunk_size)
  |> Stream.each(fn baguettes_chunk ->
    # eat them
  end)
  |> Stream.run()
end)
Link to this function

update(blob, attrs, opts \\ [])
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.

##Example

{:ok, updated_baguette} = Baguettes.update(baguette, %{kind: :best})