W3cubDocs

/Phoenix

Ecto.Adapter.Schema behaviour

Specifies the schema API required from adapters.

Summary

Types

adapter_meta()

Proxy type to the adapter meta

constraints()
fields()
filters()
on_conflict()
options()
returning()
schema_meta()

Ecto.Schema metadata fields

Callbacks

autogenerate(field_type)

Called to autogenerate a value for id/embed_id/binary_id

delete(adapter_meta, schema_meta, filters, options)

Deletes a single struct with the given filters

insert(adapter_meta, schema_meta, fields, on_conflict, returning, options)

Inserts a single new struct in the data store

insert_all(adapter_meta, schema_meta, header, list, on_conflict, returning, options)

Inserts multiple entries into the data store

update(adapter_meta, schema_meta, fields, filters, returning, options)

Updates a single struct with the given filters

Types

adapter_meta()

adapter_meta() :: Ecto.Adapter.adapter_meta()

Proxy type to the adapter meta

constraints()

constraints() :: Keyword.t()

fields()

fields() :: Keyword.t()

filters()

filters() :: Keyword.t()

on_conflict()

on_conflict() ::
  {:raise, list(), []}
  | {:nothing, list(), [atom()]}
  | {[atom()], list(), [atom()]}
  | {Ecto.Query.t(), list(), [atom()]}

options()

options() :: Keyword.t()

returning()

returning() :: [atom()]

schema_meta()

schema_meta() :: %{
  autogenerate_id:
    {schema_field :: atom(), source_field :: atom(), Ecto.Type.t()},
  context: term(),
  prefix: binary() | nil,
  schema: atom(),
  source: binary()
}

Ecto.Schema metadata fields

Callbacks

autogenerate(field_type)

autogenerate(field_type :: :id | :binary_id | :embed_id) :: term() | nil

Called to autogenerate a value for id/embed_id/binary_id.

Returns the autogenerated value, or nil if it must be autogenerated inside the storage or raise if not supported.

delete(adapter_meta, schema_meta, filters, options)

delete(adapter_meta(), schema_meta(), filters(), options()) ::
  {:ok, fields()} | {:invalid, constraints()} | {:error, :stale}

Deletes a single struct with the given filters.

While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) be given as a filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

insert(adapter_meta, schema_meta, fields, on_conflict, returning, options)

insert(
  adapter_meta(),
  schema_meta(),
  fields(),
  on_conflict(),
  returning(),
  options()
) :: {:ok, fields()} | {:invalid, constraints()}

Inserts a single new struct in the data store.

Autogenerate

The primary key will be automatically included in returning if the field has type :id or :binary_id and no value was set by the developer or none was autogenerated by the adapter.

insert_all(adapter_meta, schema_meta, header, list, on_conflict, returning, options)

insert_all(
  adapter_meta(),
  schema_meta(),
  header :: [atom()],
  [fields()],
  on_conflict(),
  returning(),
  options()
) :: {integer(), [[term()]] | nil}

Inserts multiple entries into the data store.

update(adapter_meta, schema_meta, fields, filters, returning, options)

update(
  adapter_meta(),
  schema_meta(),
  fields(),
  filters(),
  returning(),
  options()
) :: {:ok, fields()} | {:invalid, constraints()} | {:error, :stale}

Updates a single struct with the given filters.

While filters can be any record column, it is expected that at least the primary key (or any other key that uniquely identifies an existing record) be given as a filter. Therefore, in case there is no record matching the given filters, {:error, :stale} is returned.

© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/ecto/Ecto.Adapter.Schema.html