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 exist

[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

[Repo] Fetches all entries from the data store.

# 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 using opts

# Fetch all french Baguettes
Baguettes.all(prefix: "francaise")
Link to this function

count()
count() :: integer()

Count number of elements

baguettes_count = Baguettes.count()
Link to this function

count(opts)
count(opts :: Keyword.t()) :: integer()

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

# 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()}
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`
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, opts \\ [])
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)
Link to this function

exist?(presence_attrs)

Test if an object with exist

Link to this function

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

[Repo] Fetches all results from the clauses.

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

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

Link to this function

find_undeleted_by(filters)
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)

Little helper to pick first record

first_baguette = Baguettes.first()
Link to this function

first(count)
first(count :: term()) :: [Ecto.Schema.t()]

Little helper to pick first records

first_baguettes = Baguettes.first(42)
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.

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

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

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

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

Link to this function

get_undeleted_by(clauses)
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)

Little helper to pick last record. the last baguette is always the best !

last_baguette = Baguettes.last()
Link to this function

last(count)
last(count :: term()) :: [Ecto.Schema.t()]

Little helper to pick last records.

last_baguettes = Baguettes.last(42)
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.

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

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.

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