Skip to content

Instantly share code, notes, and snippets.

@christhekeele
Last active August 31, 2018 08:42
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christhekeele/c83c9c56fddf4e6a588861a646f77a69 to your computer and use it in GitHub Desktop.
Scaffold for a full implementation of the Ecto Adapter behaviours. (Ecto v2.1.4)
defmodule Ecto.Adapter.Custom do
####
# Ecto.Adapter
##
# TYPES
# @type t :: Ecto.Adapter.t
@type t :: Ecto.Adapter.Custom
@type query_meta
:: %{
prefix: binary | nil,
sources: tuple,
assocs: term,
preloads: term,
select: term,
fields: [term]
}
@type schema_meta
:: %{
source: source,
schema: atom,
context: term,
autogenerate_id: {atom, :id | :binary_id}
}
@type source
:: {prefix :: binary | nil, table :: binary}
@type fields
:: Keyword.t
@type filters
:: Keyword.t
@type constraints
:: Keyword.t
@type returning
:: [atom]
@type prepared
:: term
@type cached
:: term
@type process
:: (field :: Macro.t, value :: term, context :: term -> term)
@type autogenerate_id
:: {field :: atom, type :: :id | :binary_id, value :: term} | nil
@type on_conflict
:: {:raise, list(), []} |
{:nothing, list(), [atom]} |
{Ecto.Query.t, list(), [atom]}
@typep repo :: Ecto.Repo.t
@typep options :: Keyword.t
# CALLBACKS
@behaviour Ecto.Adapter
# Ecto.Adapter.__before_compile__/1
#? @spec __before_compile__(term, env :: Macro.Env.t) :: Macro.t # <- extra term in docs?
# @spec __before_compile__(env :: Macro.Env.t) :: Macro.t
defmacro __before_compile__(_env) do
end
# Ecto.Adapter.autogenerate/1
@spec autogenerate(field_type :: :id | :binary_id | :embed_id)
:: term |
nil |
no_return
def autogenerate(_field_type) do
end
# Ecto.Adapter.child_spec/2
@spec child_spec(repo, options)
:: Supervisor.Spec.spec
def child_spec(_repo, _options) do
end
# Ecto.Adapter.delete/4
@spec delete(repo, schema_meta, filters, options)
:: {:ok, fields} |
{:invalid, constraints} |
{:error, :stale} |
no_return
def delete(_repo, _schema_meta, _filters, _options) do
end
# Ecto.Adapter.dumpers/2
@spec dumpers(primitive_type :: Ecto.Type.primitive, ecto_type :: Ecto.Type.t)
:: [(term -> {:ok, term} | :error) | Ecto.Type.t]
def dumpers(_primitive_type, _ecto_type) do
end
# Ecto.Adapter.ensure_all_started/2
@spec ensure_all_started(repo, type :: :application.restart_type)
:: {:ok, [atom]} |
{:error, atom}
def ensure_all_started(_repo, _restart_type) do
end
# Ecto.Adapter.execute/6
@spec execute(repo, query_meta, query, params :: list, process | nil, options)
:: result
when
result: {integer, [[term]] | nil} | no_return,
query:
{:nocache, prepared} |
{:cached, (prepared -> :ok), cached} |
{:cache, (cached -> :ok), prepared}
def execute(_repo, _query_meta, _query, _params, _process, _options) do
end
# Ecto.Adapter.insert/6
@spec insert(repo, schema_meta, fields, on_conflict, returning, options)
:: {:ok, fields} |
{:invalid, constraints} |
no_return
def insert(_repo, _schema_meta, _fields, _on_conflict, _returning, _options) do
end
# Ecto.Adapter.insert_all/7
@spec insert_all(repo, schema_meta, header :: [atom], [fields], on_conflict, returning, options)
:: {integer, [[term]] | nil} |
no_return
def insert_all(_repo, _schema_meta, _header, _rows, _on_conflict, _returning, _options) do
end
# Ecto.Adapter.loaders/2
@spec loaders(primitive_type :: Ecto.Type.primitive, ecto_type :: Ecto.Type.t)
:: [(term -> {:ok, term} | :error) | Ecto.Type.t]
def loaders(_primitive_type, _ecto_type) do
end
# Ecto.Adapter.prepare/2
@spec prepare(atom :: :all | :update_all | :delete_all, query :: Ecto.Query.t)
:: {:cache, prepared} |
{:nocache, prepared}
def prepare(_type, _query) do
end
# Ecto.Adapter.update/6
@spec update(repo, schema_meta, fields, filters, returning, options)
:: {:ok, fields} |
{:invalid, constraints} |
{:error, :stale} |
no_return
def update(_repo, _schema_meta, _fields, _filters, _returning, _options) do
end
####
# Ecto.Adapter.Storage
##
# CALLBACKS
@behaviour Ecto.Adapter.Storage
# Ecto.Adapter.Storage.storage_down/1
@spec storage_down(options :: Keyword.t)
:: :ok |
{:error, :already_down} |
{:error, term}
def storage_down(_options) do
end
# Ecto.Adapter.Storage.storage_up/1
@spec storage_up(options :: Keyword.t)
:: :ok |
{:error, :already_up} |
{:error, term}
def storage_up(_options) do
end
####
# Ecto.Adapter.Migration
##
# TYPES
@type command
:: raw :: String.t |
{:create, Table.t, [table_subcommand]} |
{:create_if_not_exists, Table.t, [table_subcommand]} |
{:alter, Table.t, [table_subcommand]} |
{:drop, Table.t} |
{:drop_if_exists, Table.t} |
{:create, Index.t} |
{:create_if_not_exists, Index.t} |
{:drop, Index.t} |
{:drop_if_exists, Index.t}
@type table_subcommand
:: {:add, field :: atom, type :: Ecto.Type.t | Reference.t, Keyword.t} |
{:modify, field :: atom, type :: Ecto.Type.t | Reference.t, Keyword.t} |
{:remove, field :: atom}
@type ddl_object :: Table.t | Index.t
# CALLBACKS
@behaviour Ecto.Adapter.Migration
# Ecto.Adapter.Migration.execute_ddl/3
@spec execute_ddl(repo :: Ecto.Repo.t, command, options :: Keyword.t)
:: :ok |
no_return
def execute_ddl(_repo, _command, _options) do
end
# Ecto.Adapter.Migration.supports_ddl_transaction?/0
@spec supports_ddl_transaction?
:: boolean
def supports_ddl_transaction? do
end
####
# Ecto.Adapter.Structure
##
# CALLBACKS
@behaviour Ecto.Adapter.Structure
# Ecto.Adapter.Structure.structure_dump/2
@spec structure_dump(default :: String.t, config :: Keyword.t)
:: {:ok, String.t} |
{:error, term}
def structure_dump(_default, _config) do
end
# Ecto.Adapter.Structure.structure_load/2
@spec structure_load(default :: String.t, config :: Keyword.t)
:: {:ok, String.t} |
{:error, term}
def structure_load(_default, _config) do
end
####
# Ecto.Adapter.Transaction
##
# CALLBACKS
@behaviour Ecto.Adapter.Transaction
# Ecto.Adapter.Transaction.in_transaction?/1
@spec in_transaction?(repo :: Ecto.Repo.t)
:: boolean
def in_transaction?(_repo) do
end
# Ecto.Adapter.Transaction.rollback/2
@spec rollback(repo :: Ecto.Repo.t, value :: any)
:: no_return
def rollback(_repo, _value) do
end
# Ecto.Adapter.Transaction.transaction/3
@spec transaction(repo :: Ecto.Repo.t, options :: Keyword.t, function :: (... -> any))
:: {:ok, any} |
{:error, any}
def transaction(_repo, _options, _function) do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment