/
adapter.ex
88 lines (73 loc) · 3.15 KB
/
adapter.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
defmodule Ecto.Adapter do
@moduledoc """
This module specifies the adapter API that an adapter is required to
implement.
"""
use Behaviour
@type t :: module
@doc """
The callback invoked when the adapter is used.
"""
defmacrocallback __using__(opts :: Keyword.t) :: Macro.t
@doc """
Starts any connection pooling or supervision and return `{:ok, pid}`
or just `:ok` if nothing needs to be done.
Returns `{:error, {:already_started, pid}}` if the repo already
started or `{:error, term}` in case anything else goes wrong.
"""
defcallback start_link(repo :: Ecto.Repo.t, options :: Keyword.t) ::
{:ok, pid} | :ok | {:error, {:already_started, pid}} | {:error, term}
@doc """
Stops any connection pooling or supervision started with `start_link/1`.
"""
defcallback stop(repo :: Ecto.Repo.t) :: :ok
@doc """
Fetches all results from the data store based on the given query.
"""
defcallback all(repo :: Ecto.Repo.t, query :: Ecto.Query.t,
params :: map(), opts :: Keyword.t) :: [[term]] | no_return
@doc """
Updates all entities matching the given query with the values given. The
query shall only have `where` expressions and a single `from` expression. Returns
the number of affected entities.
"""
defcallback update_all(repo :: Ecto.Repo.t, query :: Ecto.Query.t,
filter :: Keyword.t, params :: map(),
opts :: Keyword.t) :: integer | no_return
@doc """
Deletes all entities matching the given query.
The query shall only have `where` expressions and a `from` expression.
Returns the number of affected entities.
"""
defcallback delete_all(repo :: Ecto.Repo.t, query :: Ecto.Query.t,
params :: map(), opts :: Keyword.t) :: integer | no_return
@doc """
Inserts a single new model in the data store.
"""
defcallback insert(repo :: Ecto.Repo.t, source :: binary,
fields :: Keyword.t, returning :: [atom],
opts :: Keyword.t) :: {:ok, tuple} | no_return
@doc """
Updates a single model with the given filters.
While `filter` can be any record column, it is expected that
at least the primary key (or any other key that uniquely
identifies an existing record) to be given as filter. Therefore,
in case there is no record matching the given filters,
`{:error, :stale}` is returned.
"""
defcallback update(repo :: Ecto.Repo.t, source :: binary,
filter :: Keyword.t, fields :: Keyword.t,
returning :: [atom], opts :: Keyword.t) ::
{:ok, tuple} | {:error, :stale} | no_return
@doc """
Deletes a sigle model with the given filters.
While `filter` can be any record column, it is expected that
at least the primary key (or any other key that uniquely
identifies an existing record) to be given as filter. Therefore,
in case there is no record matching the given filters,
`{:error, :stale}` is returned.
"""
defcallback delete(repo :: Ecto.Repo.t, source :: binary,
filter :: Keyword.t, opts :: Keyword.t) ::
{:ok, tuple} | {:error, :stale} | no_return
end