EctoCrux.Schema.Baguettes (EctoCrux v1.2.8)
Sample module using EctoCrux
Link to this section Summary
Functions
[Repo] Fetches all entries from the data store
call schema_module changeset method
Count number of elements
Count number of entries with opts
Count number of entries from a query with opts
[Repo proxy of insert/2] Create (insert) a new baguette from attrs
Create (insert) a baguette from attrs if it doesn't exist
[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 proxy] Deletes a struct using its primary key.
Test if an entry with <presence_attrs> exists
[Repo] Fetches all results from the filter clauses.
[Repo] Fetches all results from the filter clauses, with opts
[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] Similar to get_by/2 but raises Ecto.NoResultsError if no record was found.
create a new query using schema module
default page size if using pagination
[Repo proxy] Preloads all associations on the given struct or structs.
value of read_only mode
configured repo to use
schema module is it associated to
Like find_by/1
by returns a stream to handle large requests
Create an atom-keyed map from the given map. If both a string and an atom keys are provided in the original map, atom key gets priority.
[Repo proxy] Updates a changeset using its primary key.
Link to this section Functions
all(opts \\ [])
Specs
all(opts :: Keyword.t()) :: [EctoCrux.Schema.Baguette.t()]
[Repo] Fetches all entries from the data store
# Fetch all Baguettes
Baguettes.all()
# Fetch all Baguettes within Repo prefix "francaise"
Baguettes.all(prefix: "francaise")
Options
- @see Repo.all/2
change(blob, attrs \\ %{})
call schema_module changeset method
count()
Specs
count() :: integer()
Count number of elements
baguettes_count = Baguettes.count()
count(query)
Specs
count(query :: Ecto.Query.t()) :: integer()
count(opts :: Keyword.t()) :: integer()
Count number of entries with opts
baguettes_count = Baguettes.count(prefix: "francaise")
Options
- @see Repo.one/2
count(query, opts)
Specs
count(query :: Ecto.Query.t(), opts :: Keyword.t()) :: integer()
Count number of entries from a query with opts
query = from b in Baguette, where :kind in ["tradition"]
baguettes_count = Baguettes.count(query, prefix: "francaise")
Options
- @see Repo.one/2
create(attrs \\ %{}, opts \\ [])
Specs
create(attrs :: map(), opts :: Keyword.t()) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
[Repo proxy of insert/2] Create (insert) a new baguette from attrs
# Create a new baguette with `:kind` value set to `:tradition`
{:ok, baguette} = Baguettes.create(%{kind: :tradition})
Options
@see Repo.insert/2
create_if_not_exist(attrs)
Specs
create_if_not_exist(attrs :: map()) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
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
Options
@see Repo.insert/2
create_if_not_exist(attrs, opts)
Specs
create_if_not_exist(attrs :: map(), opts :: Keyword.t()) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
create_if_not_exist(presence_attrs :: map(), creation_attrs :: map()) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
[Repo] Create (insert) a baguette from attrs if it doesn't exist
Behave like create_if_not_exist/1
but you can specify attrs for the presence test, and creation attrs.
Options
@see Repo.insert/2
create_if_not_exist(presence_attrs, creation_attrs, opts)
Specs
create_if_not_exist( presence_attrs :: map(), creation_attrs :: map(), opts :: Keyword.t() ) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
[Repo] Create (insert) a baguette from attrs if it doesn't exist
Behave like create_if_not_exist/1
but you can specify attrs for the presence test, and creation attrs.
Options
@see Repo.insert/2
delete(blob, opts \\ [])
Specs
delete(blob :: EctoCrux.Schema.Baguette.t(), opts :: Keyword.t()) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
[Repo proxy] Deletes a struct using its primary key.
= Baguettes.delete(baguette)
Options
- @see Repo.delete/2
exist?(presence_attrs, opts \\ [])
Specs
Test if an entry with <presence_attrs> exists
find_by(query)
Specs
[Repo] Fetches all results from the filter clauses.
best_baguettes = Baguettes.find_by(kind: "best")
find_by(query, opts)
Specs
[Repo] Fetches all results from the filter clauses, with opts
best_baguettes = Baguettes.find_by(kind: "best", prefix: "francaise")
Options
- @see Repo.all/2
get(id, opts \\ [])
Specs
[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])
Options
preloads
- list of atom to preload- @see Repo.insert/2
get!(id, opts \\ [])
Specs
[Repo] Similar to get/2 but raises Ecto.NoResultsError if no record was found.
Options
preloads
- list of atom to preload- @see Repo.insert/2
get_by(clauses, opts \\ [])
Specs
[Repo] Fetches a single result from the clauses.
best_baguette = Baguettes.get_by(kind: "best")
Options
preloads
- list of atom to preload- @see Repo.insert/2
get_by!(clauses, opts \\ [])
Specs
[Repo] Similar to get_by/2 but raises Ecto.NoResultsError if no record was found.
Options
preloads
- list of atom to preload- @see Repo.insert/2
init_query()
create a new query using schema module
offset_to_page(offset, page_size)
page_size()
default page size if using pagination
page_to_offset(page, page_size)
preload(blob, preloads, opts \\ [])
Specs
preload(structs_or_struct_or_nil, preloads :: term(), opts :: Keyword.t()) :: structs_or_struct_or_nil when structs_or_struct_or_nil: [EctoCrux.Schema.Baguette.t()] | EctoCrux.Schema.Baguette.t() | nil
[Repo proxy] Preloads all associations on the given struct or structs.
my_baguette = Baguettes.preload(baguette, [:floor, :boulanger])
Options
- @see Repo.preload/2
read_only()
value of read_only mode
repo()
configured repo to use
schema_module()
schema module is it associated to
stream(filters, opts \\ [])
Specs
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)
Options
- @see Repo.stream/2
to_schema_atom_params(mixed_keyed_map)
Create an atom-keyed map from the given map. If both a string and an atom keys are provided in the original map, atom key gets priority.
Baguettes.to_schema_atom_params(%{"kind" => "baguepi", :kind => "tradition", "half?" => true})
%{kind: "tradition"}
update(blob, attrs, opts \\ [])
Specs
update( blob :: EctoCrux.Schema.Baguette.t(), attrs :: map(), opts :: Keyword.t() ) :: {:ok, EctoCrux.Schema.Baguette.t()} | {:error, Ecto.Changeset.t()}
[Repo proxy] Updates a changeset using its primary key.
{:ok, updated_baguette} = Baguettes.update(baguette, %{kind: "best"})
Options
- @see Repo.update/2